0
這是_.initial
underscore.js
的代碼:_.initial比它需要在Underscore.js中更詳細嗎?
// Returns everything but the last entry of the array. Especially useful on
// the arguments object. Passing **n** will return all the values in
// the array, excluding the last N.
_.initial = function(array, n, guard) {
return slice.call(array, 0, Math.max(0, array.length - (n == null || guard ? 1 : n)));
};
在我看來,以下將不再繁瑣,相當於:
_.initial = function(array, n, guard) {
return slice.call(array, 0, Math.min(0, -(n == null || guard ? 1 : n)));
};
問這樣一個細節是不出來的地方,因爲underscore.js
嘗試保存儘可能多的字節。舉例來說,這個評論:
// Save bytes in the minified (but not gzipped) version:
var ArrayProto = Array.prototype, ObjProto = Object.prototype, FuncProto = Function.prototype;
是否有更詳細的代碼的原因?