Extending Object.prototype JavaScript

UPDATE from 2021

Despite this being the accepted answer, 10 years of experience has taught me this isn’t the best idea. Pretty much anything you can do avoid polluting the global scope is a very very good thing.

Original answer below, for posterity, and because stack overflow will not let me delete an accepted answer.


Original answer from 2011

I think it’s fine if it works in your target environment.

Also I think prototype extension paranoia is overblown. As long as you use hasOwnProperty() like a good developer that it’s all fine. Worst case, you overload that property elsewhere and lose the method. But that’s your own fault if you do that.

Leave a Comment