> If it's so BAD why Douglas Crockford in his book[1] has no 
> problem with object.prototype augmentation ?
> 
> For example, take a look : 
> http://javascript.crockford.com/prototypal.html
> He says : "The problem with Object.prototype.begetObject is 
> that it trips up incompetent programs[..]"
> 
> 
> [1] http://oreilly.com/catalog/9780596517748/

Doug's a very smart guy, and a world-class JavaScript expert. However, there
are a few things like this where he's not really looking at all the
tradeoffs. (That's a polite way of saying "he's wrong!")

On this particular issue, Doug wishes JavaScript had a feature it doesn't
have - the ability to add non-enumerable properties to an object or its
prototype. So, he's willing to push the burden of dealing with this
limitation onto every for..in loop in existence. That means you can never
write a clean and simple for..in loop again: instead, you have to use (ugh!)
a Design Pattern.

Consider Doug's JSON library, which until recently extended
Object.prototype, and as a result all sorts of code around the world broke
in odd ways. Not just jQuery, but anyone who innocently used a for..in loop
and expected it to work as advertised.

The newest version of Doug's JSON library no longer extends
Object.prototype.

-Mike

Reply via email to