Javascript 1.9.3 / ECMAScript 5 introduces Object.create
, which Douglas Crockford amongst others has been advocating for a long time. How do I replace new
The advantage is that Object.create
is typically slower than new
on most browsers
In this jsperf example, in a Chromium, browser new
is 30 times as fast as Object.create(obj)
although both are pretty fast. This is all pretty strange because new does more things (like invoking a constructor) where Object.create should be just creating a new Object with the passed in object as a prototype (secret link in Crockford-speak)
Perhaps the browsers have not caught up in making Object.create
more efficient (perhaps they are basing it on new
under the covers ... even in native code)