scottcorgan / tiny-emitter

A tiny (less than 1k) event emitter library
MIT License
935 stars 67 forks source link

Don't use for (var i in evts) to iterate over arrays #4

Closed lazd closed 10 years ago

lazd commented 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.

Use a for loop.

scottcorgan commented 10 years ago

Thanks for the heads up!