“新对象()”和“对象字面符号”有什么区别?用于创建对象的基于构造函数的语法有什么区别:person = new Object().这个字面语法:person = {
property1 : "Hello"};虽然JSLint更喜欢使用对象文字表示法,但两者似乎都在做相同的事情。哪个更好,为什么?
3 回答

白板的微信
TA贡献1883条经验 获得超3个赞
new Object()
person = new Object() /*You should put a semicolon here too. It's not required, but it is good practice.*/ -or-person = { property1 : "Hello"};
Object
// Don't do thisObject = 23;
new Object
{}
new Object
{}

汪汪一只猫
TA贡献1898条经验 获得超8个赞
function Obj( prop ) { return { p : prop, sayHello : function(){ alert(this.p); }, }; }
function Obj( prop ) { this.p = prop; } Obj.prototype.sayHello = function(){alert(this.p);};
Obj
var foo = new Obj( "hello" );
sayHello
添加回答
举报
0/150
提交
取消