|
|
|
|
|
by MatthewPhillips
5185 days ago
|
|
I just use Object.create[1]. Constructor functions give the illusion of classical inheritance but JavaScript doesn't have classical inheritance and I think it's best to simply break the notion off from your brain by not using stuff that makes JS appear to be something it is not. JavaScript uses prototypes. Prototypes or just objects from which you derive other objects. Object.create makes this very obvious. Under the hood you are still using prototypes in the same way as you would by using constructor functions you just don't have to worry about the Constructor.prototype object as it is abstracted from view. The second biggest problem with the method you are using (after performance/memory consumption) is not having access to either instanceof or isPrototypeOf. If you are doing anything complicated having access to one of those two can by crucial. [1]https://developer.mozilla.org/en/JavaScript/Reference/Global... |
|
http://www.w3counter.com/globalstats.php?year=2011&month...
http://kangax.github.com/es5-compat-table/
and you really dont expect anyone to write clunky property descriptors like this??
https://developer.mozilla.org/en/JavaScript/Reference/Global...