Here to take an example of adding events
Copy Code code as follows:
Mode 1
function Addevent (EL, type, fn) {
if (El.addeventlistener) {
El.addeventlistener (Type, FN, false);
}else{
El.attachevent (' On ' +type, FN)
}
}
Mode 2
var addevent = Document.addeventlistener?
Function (el, type, fn) {El.addeventlistener (type, FN, false);}:
Function (el, type, fn) {el.attachevent (' on ' +type, FN)};
Mode 1 in the function to make judgments, every time to add events to the element need to be judged once, the efficiency is relatively low.
JQuery 1.6.1/prototype 1.7/mootools 1.3/tangram 1.3.6/reg.js/right.js are all used in this way.
Mode 2 uses two anonymous functions, which are only judged once during initialization, and are not required to be judged every time it is invoked. Efficiency is relatively high.
Ext/kissy/qwrap uses this branch of writing.