条件预加载(conditional advanceloading)

 1 var addHandler = document.body.addEventListener ?

 2 function(target, eventType, handler) {

 3 target.addEventListener(eventType, handler, false);

 4 } : function(target, eventType, handler) {

 5 target.attachEvent("on" + eventType, handler);

 6 };

 7

 8 var removeHandler = document.body.removeEventListener ?

 9 function(target, eventType, handler) {

10 target.removeEventListener(eventType, handler, false);

11 } : function(target, eventType, handler) {

12 target.detachEvent("on" + eventType, handler);

13 };

 

预加载适用于一个函数马上要被用到,并且在整个页面的生命周期中频繁出现的场合。 

你可能感兴趣的:(Condition)