Comment on Stop Using Constructors in JS (2012)parentComments−swartkrans11ythe 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-newWhy would it `always outperform` though? Seems like an implementation detail. Object.create should be faster since it doesn't run a constructor.−phpnode11yThe ever-wonderful Vyacheslav Egorov has a nice article on this:http://mrale.ph/notes/constructor-vs-objectcreate.html−drinchev11yI bet this is because most of JS compilers are optimized in lower level for certain "popular" tasks, developers use to do.
Comments
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.