fortnightlabs/pos-js — pull request #7 by dariusk (2013-12-16 13:48:41+00:00)
Title: Filter `for in` loops in lexer.js to prevent prototype collisions

This change fixes an error in the way the lexer loops through words. At the moment
a basic `for in` loop is used -- 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.

For more info on `hasOwnProperty` as a `for in` filter, see:
http://bonsaiden.github.io/JavaScript-Garden/#object.forinloop