Skip to content

Comment on Stop Using Constructors in JS (2012)parent

Comments

the biggest one is probably performance, `new Foo` will always outperform `Object.create(FooProto)`.

He's right, `new` is more than 10x faster in Chrome and Firefox for me at least:

http://jsperf.com/create-new

Why would it `always outperform` though? Seems like an implementation detail. Object.create should be faster since it doesn't run a constructor.

The ever-wonderful Vyacheslav Egorov has a nice article on this:

http://mrale.ph/notes/constructor-vs-objectcreate.html

I bet this is because most of JS compilers are optimized in lower level for certain "popular" tasks, developers use to do.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.