jQuery新旧版本共存
1 | <script src="jquery-1.5.js"></script> |
1 | <script src="jquery-1.5.js"></script> |
简单的for-in(事件)
1 | for ( type in events ) {} |
缓存length属性,避免每次都去查找length属性,稍微提升遍历速度。
但是如果遍历HTMLCollection时,性能提升非常明显,因为每次访问HTMLCollection的属性,HTMLCollection都会内部匹配一次所有的节点
1 | for ( var j = 0, l = handlers.length; j < l; j++ ) {} |
不比较下标,直接判断元素是否为true(强制类型转换)
1 | var elem; |
1 | (function(window, undefined){ |
1 | undefined = "now it's defined"; |