Are the following statements in javascript equivalent? [duplicate]
Possible Duplicates:
Is there a reason not to usenew Object()
in JavasScript? Create an empty object in JavaScript with {} or new Object()?
In javascript, are the following two statements equivalent?
var c = new Object();
var c = {};
Yes. From §11.1.5 Object Initialiser:
The production ObjectLiteral : { } is evaluated as follows:
Return a new object created as if by the expression new Object() where Object is the standard built-in constructor with that name.
精彩评论