How to avoid jslint to shout at me with the warning
'Expected 'Object.create(null)' and instead saw 'new Object'
when using this very simple line of code:
var myDummyObject = new Object();
?
Well, jslint is opinionated and you use it because you want to know its opinion about things. Apparently, it has an opinion that new Object()
should not be used. The issue you see is documented here: http://www.jslint.com/help.html. It does not say why.
Lots of discussion about it here: What is the difference between new Object()
and object literal notation?. The {}
syntax is both faster and shorter than new Object()
which sounds like enough of a reason to prefer it.
As you apparently know, you can use either of these:
var myDummyObject = {};
var myDummyObject = Object.create(null);
The latter will create an object with an empty prototype so it won't have methods on it like .hasOwnProperty()
which is occasionally useful though usually not needed.