justmoon / node-extend

Simple function to extend objects
MIT License
341 stars 68 forks source link

why the isArray stuff? #36

Closed coderofsalvation closed 8 years ago

coderofsalvation commented 8 years ago

I was just wondering why this extend() does more then for example this one: https://gist.github.com/coderofsalvation/8239d9362744896f766c

why the isArray stuff? Is it for browser compatibility reasons?

ljharb commented 8 years ago

Relying on the constructor property is something that should be avoided whenever possible. Using an indirect Array() and Object() to construct [] and {} are also unclear and inefficient. Also, using for..in on an array is a bad idea because it will enumerate all properties on the prototype, which isn't the semantic one often wants.