Dies ist underscore.js
‚s-Code für _.initial
:Ist _.initial ausführlicher als es in Underscore.js sein muss?
// 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)));
};
Es scheint mir, dass weniger ausführlich und gleichwertig wäre folgendes:
_.initial = function(array, n, guard) {
return slice.call(array, 0, Math.min(0, -(n == null || guard ? 1 : n)));
};
über Fragen eine solche Details deplatziert nicht, weil underscore.js
versucht, so viele Bytes wie möglich zu speichern. Nehmen wir zum Beispiel, diesen Kommentar:
// Save bytes in the minified (but not gzipped) version:
var ArrayProto = Array.prototype, ObjProto = Object.prototype, FuncProto = Function.prototype;
Gibt es einen Grund für die ausführlichere Code?