我不明白为什么在这一行的 changeName 之后没有 () this.chngName = changeName;
。我的逻辑是this.chngName
分配给函数返回,函数最后有一个 ()。谢谢回答。
function person(firstname, lastname, age, eyecolor) {
this.firstname = firstname;
this.lastname = lastname;
this.age = age;
this.eyecolor = eyecolor;
this.chngName = changeName;
function changeName(name) {
this.lastname = name;
}
}
myMother = new person("Sally", "Rally", 48, "green");
myMother.chngName("Doe");
document.write(myMother.lastname);