glejeune / node-graphviz

Node.js interface to the GraphViz graphing tool
http://algorithmique.net
MIT License
197 stars 58 forks source link

Fixing `for in` loops #17

Closed dariusk closed 10 years ago

dariusk commented 10 years ago

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.

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

dariusk commented 10 years ago

Thought I would ping again on here.