Lazy loading implementation code of js function_javascript skills
May 16, 2016 pm 05:49 PM
Lazy loading
Copy code The code is as follows:
//For non-delayed loading functions, conditional judgment will be performed every time it is called.
removefunctionHandler(target, eventType, handler) {
if(target.removeEventListener) {
target.removeEventListener(eventType,handler,false);
}else {
target.detachEvent( "on" eventType,handler);
}
}
//The delayed loading function will overwrite the original old function after the first call. The new function will be called again in the future and will not be called again. Make conditional judgments to improve efficiency
function addHandler(target, eventType, handler) {
if(target.addEventListener) {
addHandler = function(target, eventType, handler){
target.addEventListener (eventType,handler,false);
}
}else{
addHandler = function(target,eventType,handler){
target.attachEvent("on" eventType,handler);
}
}
addHandler(target, eventType, handler);
}
//Conditional preloading
//Conditional preloading ensures that all function calls take the same time. The cost is instrumentation when the script loads. Preloading is suitable for situations where a function will be used immediately and is used frequently throughout the page life cycle.
var addEventHandler = document.body.addEventListener ? function(target,eventType,handler) {
target.addEventListener(eventType,handler,false);
} : function(target,eventType,handler) ) {
target.attachEvent("on" eventType,handler);
}
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot tools Tags

Hot Article
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

What is the architecture and working principle of Spring Data JPA?

Java JPA performance optimization tips: make your application fly

How does Hibernate optimize database query performance?

What is the original meaning of dynamic linking and static linking in Linux?

Decoding Laravel performance bottlenecks: Optimization techniques fully revealed!

What to do if the html image is too large

What are the disadvantages of Hibernate ORM framework?
