我需要一些帮助,有人可以向我解释为什么我在创建对象时必须使用new吗?
我这样创建了一些对象:
var person = {
firstName: "Danny",
lastName: "Black",
age: 20,
display: function(){
document.write("My name is " + this.firstName + " " + this.lastName + " and my age is " + this.age);
}
}
var example = new person.display();
document.getElementById("firstObject").innerHTML = example;
而且比这样:
var anotherExample = new person.display();
document.getElementById("firstObject").innerHTML = anotherExample;
有什么区别?