0

I've seen lots of Stack Overflow javascript questions whose answers include modifying prototypes of primitive types (such as this). But many times the highest upvoted answer does not use a prototype mod.

This made me wonder, other than possibly a few lost milliseconds from efficiency, what are the pros and cons of prototype modification?

Neil
  • 1,275
  • 11
  • 25
  • As a concrete example: if you extend `Object.prototype.thing = 'thing'` and some library you use expects `var obj = { thing: 'other' }; delete obj.thing;` to result in an `obj` without a `thing`, it’ll be unpleasantly surprised. (This is kind of contrived and such libraries should usually use a prototypeless object instead, but it’s the potential for distant side-effects that makes it just simpler to use regular old functions in your own scope.) – Ry- Aug 18 '17 at 05:40
  • the only time to extend "native" objects (Array, String etc) would be to add new standard features to internet exploder and safari – Jaromanda X Aug 18 '17 at 05:43

0 Answers0