Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is using Prototype to extend native objects bad? [closed]

I read somewhere that using prototype to extend native objects (String, Number, Array, etc.) was a bad idea. Is this true? Why or why not?

like image 379
Elliot Bonneville Avatar asked Apr 17 '12 18:04

Elliot Bonneville


Video Answer


2 Answers

I don't think it's bad. If you have a look at Ruby on Rails, very many native objects are extended with custom functionality and it's a very good framework.

What would be bad is if you change existing methods on native objects. this could cause unforseen consequences.

like image 136
Andreas Linden Avatar answered Sep 23 '22 03:09

Andreas Linden


There's a great discussion about this in this video from JSConf 2011 by Andrew Dupont. http://blip.tv/jsconf/jsconf2011-andrew-dupont-everything-is-permitted-extending-built-ins-5211542

Basically the points are:

  • Don't extend Object.prototype
  • Some people might like to extend things, some people don't
  • You need to know what you're doing
  • Don't use two libraries that extend things, because it can be bad
  • Extending prototypes to add standard functionality is almost always ok.
like image 31
Jamund Ferguson Avatar answered Sep 21 '22 03:09

Jamund Ferguson