On 27 May 2013 08:55, Sanford Whiteman <[email protected]> wrote: > Please put an example in jsfiddle.net to check out. There is certainly > nothing in Moo that will "break" for-in in JS. >
.. Er. Yes, there is, though it is not MooTools' fault. MooTools is prototypal. It extends natives, including Array. When iterating through array members with a `for in` construct, it will also loop through enumerable properties from the proto. Two things. 1. use `hasOwnProperty` to check the property is on the array; or--better-yet, 2: don't use an operator meant for looping Object keys on an Array. It works, because Arrays in JavaScript are Objects with extra Array-like properties but that's not the point. There are very few cases where you'd use this on purpose, eg. sparse arrays. MooTools has `Array.prototype.each` for working with Arrays. ES5 has `.forEach`. -- Dimitar Christoff "JavaScript is to JAVA what hamster is to ham" @D_mitar - https://github.com/DimitarChristoff -- --- You received this message because you are subscribed to the Google Groups "MooTools Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
