functionperson(firstname,lastname,age,eyecolor){this.firstname=firstname;this.lastname=lastname;this.age=age;this.eyecolor=eyecolor;this.changeName=changeName;functionchangeName(name){this.lastname=name;}}varcont="";myMother=newperson("Steve","Jobs",56,"green");myMother.changeName("Ballmer");for(variinmyMother){cont+=i+":"+myMother[i]+"
";}document.write(cont);本人新手,在对JS中的对象方法的调用中对例子产生疑惑,JS中调用方法直接用object.method()就行了,为什么在上面代码中还需要添加这一句代码呢this.changeName=changeName;如果把这一句删除了就会显示myMother.changeNameisnotafunction为什么需要在person中添加1个changeName属性才行呢?
www说
胡子哥哥
相关分类