1. 緩存原型,考慮訪問速度javascript
var push = ArrayProto.push, slice = ArrayProto.slice, concat = ArrayProto.concat, toString = ObjProto.toString, hasOwnProperty = ObjProto.hasOwnProperty;
2. 判斷數組是否支持forEach方法,判斷對象是否有此原型方法php
nativeForEach && obj.forEach === nativeForEach
3. Object.keys方法返回對象自身可枚舉的屬性,不一樣於hasOwnProperty方法會繼承上級屬性java
4. 函數參數個數多於65535個時,Math.max.apply(Math, array)會發生範圍溢出錯誤web
https://bugs.webkit.org/show_bug.cgi?id=80797數組
5. 緩存
var arr = [1,2,3,4], arr1= [5,6,7,8]; // arr.push.apply(arr,arr1) == arr.push(5,6,7,8)
6. 數組初始化時,明確長度後再賦值性能較好,參考 http://jsperf.com/array-init-ivonapp
var pairs = new Array(length); for (var i = 0; i < length; i++) { pairs[i] = [keys[i], obj[keys[i]]]; }
7. 數字0與-0的區別ecmascript
// Identical objects are equal. `0 === -0`, but they aren't identical. // See the [Harmony `egal` proposal](http://wiki.ecmascript.org/doku.php?id=harmony:egal). if (a === b) return a !== 0 || 1 / a == 1 / b; // 1/0 ===Infinity, 1/-0 === -Infinity