function person(firstname,lastname,age,eyecolor){ this.firstname=firstname; this.lastname=lastname; this.age=age; this.eyecolor=eyecolor; this.changeName=changeName; function changeName(name){ this.lastname=name; } } myMother=new person("Sally","Rally",48,"green"); myMother.changeName("Doe"); document.write(myMother.lastname);
下面代码中,如果说this指向调用它的函数,那么下面的this不是指向changeName.
那么changeName.lastname不是undifined么。
function changeName(name){ this.lastname=name; }
Caballarii
相关分类