First of all, I made a quick jsperf test case to show the obvious :
Object.create(null)
is way slower than creating a object with the {}
syntax.
http://jsperf.com/js-object-creation-null-proto
But given this fact, can the former case be a good alternative sometimes concerning optimization and performance? In other words, does manipulating the most lightweight js object can increase performance enough so that it became a reasonable choice to use it in some cases.
I am refering to cases where you are going to access the object properties a lot, or making an heavy use of the for in loop for example.
Is this method too much risky to be used in a library where people could be lead to heandle these object that doesn't own the standard properties bring by the standard Object
prototype?
Also, do you know another (quicker) way to create the most lightweight js object?
PS : I made a brief test case to show a case where using a Object.create(null)
and accessing properties is a little more quickier than with {}
.
http://jsperf.com/js-object-creation-and-accessing-properties