Closed lazd closed 10 years ago
This approach is inherently brittle if an enumerable property has been added to the array prototype:
Array.prototype.last = function() { return this.length && this[this.length-1] || null; };
Yes, the above code is bad-practice (at least use Object.defineProperty to make it non-enumerable), but your library cannot be sure that arrays will not have been abused as such.
Object.defineProperty
Use a for loop.
for
Thanks for the heads up!
This approach is inherently brittle if an enumerable property has been added to the array prototype:
Yes, the above code is bad-practice (at least use
Object.defineProperty
to make it non-enumerable), but your library cannot be sure that arrays will not have been abused as such.Use a
for
loop.