【发布时间】:2015-02-11 05:27:26
【问题描述】:
看起来有多种方法可以在 Javascript 中创建对象,如下所示:
var person = {
firstName:"John",
lastName:"Doe",
age:50,
eyeColor:"blue"
};
function person(){
this.firstName = 'first';
this.lastName = 'last';
this.age = 'age';
this.eyeColor = 'eyecolor';
}
person = (function () {
this.firstName = 'first';
this.lastName = 'last';
this.age = 'age';
this.eyeColor = 'eyecolor';
}();
有人可以帮我理解以上哪一种是最好的做法吗?
还有我们在什么场景下使用自调用功能?
【问题讨论】:
-
这取决于你以后想对这些对象做什么,所以真的没有最好的方法。
标签: javascript