Why is it frowned upon to modify JavaScript object's prototypes?

colourandcode picture colourandcode · Jun 3, 2011 · Viewed 7.4k times · Source

I've come across a few comments here and there about how it's frowned upon to modify a JavaScript object's prototype? I personally don't see how it could be a problem. For instance extending the Array object to have map and include methods or to create more robust Date methods?

Answer

bjornd picture bjornd · Jun 3, 2011

The problem is that prototype can be modified in several places. For example one library will add map method to Array's prototype and your own code will add the same but with another purpose. So one implementation will be broken.