3 ms·
To repeat myself: Just because Crockford suggests it, doesn't make it a good idea. Here's a set of benchmarks for creating a new instance, using the pattern yo
by jashkenas 16y ago
To repeat myself: Just because Crockford suggests it, doesn't make it a good idea.
Here's a set of benchmarks for creating a new instance, using the pattern you just linked to (called "Crockford Create" within):
http://jsperf.com/object-create-vs-crockford-vs-jorge-vs-constructor/9 http://jsperf.com/object-create-vs-crockford-vs-jorge-vs-con...
In Safari, it's about 5X slower than using a regular constructor function. In Chrome, it's about 20X slower.
In JS, just using prototypes as Eich intended is the way to go.
- praptak 16y ago"To repeat myself: Just because Crockford suggests it, doesn't make it a good idea." I did not suggest anything like this. My point was that Crockford pretty much enumerates every sensible way to do inheritance in JS, with the conclusion quite similar to yours - Crockford suggests (in fact: describes) many things, so don't draw too much from this. Btw, he suggests the regular constructor too: http://javascript.crockford.com/inheritance.html http://javascript.crockford.com/inheritance.html