4 ms·
What's the current consensus on augmentation of built-in prototypes [1]? Is it still a contentious issue? [1] http://michaux.ca/articles/javascript-the-good-pa
by rudiger 15y ago
What's the current consensus on augmentation of built-in prototypes [1]? Is it still a contentious issue?
[1] http://michaux.ca/articles/javascript-the-good-parts-built-in-object-augmentation-and-namespacing http://michaux.ca/articles/javascript-the-good-parts-built-i...
- dstein 15y agoYou're okay as long as you don't extend Object which only leads to "hasOwnProperty" messiness. In cases where I might want to extend Object I use a static Object.foo(object) instead.
- kemayo 15y agoObject.prototype aside, I think it's a bad habit in any sort of large-ish system. Partially because of namespacing concerns; if prototype-extension happens in libraries you use, you might have common things like "startsWith" clobber each other with subtle incompatibilities. There's also visibility concerns. If you add random methods to things that look like language primitives it can be hard to get an overview of where they're really being used. Anecdotally, I had to go through and remove all use of prototype.js from deviantART because we decided to standardize on jQuery. It was a pain. A serious, serious pain. Because prototype.js extended Array, String, and other objects. So I had to go make a list of every single method that prototype.js added to these, and find all incidences of those somewhat-common strings in our codebase and examine them case-by-case to see if they were actually calling the prototype.js versions. By contrast, if I'd wanted to remove all use of jQuery I could have built an unambiguous list of all uses with a fairly simple grep.