This library uses several for in loops -- but for in traverses the prototype chain,
which means that the lexer throws an error if anything is attached to, for example,
Array.prototype. (I have an Array.prototype.pick function that returns a random
element from an array, which broke this library.)
By adding if (collection.hasOwnProperty(i)) to each for in loop, we avoid
looping over things added to the prototype, looping only over properties that are
'really' in the collection.
This library uses several
for in
loops -- butfor in
traverses the prototype chain, which means that the lexer throws an error if anything is attached to, for example,Array.prototype
. (I have anArray.prototype.pick
function that returns a random element from an array, which broke this library.)By adding
if (collection.hasOwnProperty(i))
to eachfor in
loop, we avoid looping over things added to the prototype, looping only over properties that are 'really' in the collection.For more info on
hasOwnProperty
as afor in
filter, see: http://bonsaiden.github.io/JavaScript-Garden/#object.forinloop