首页 > 代码库 > 记录把方法添加到 JavaScript 对象不明白的地方

记录把方法添加到 JavaScript 对象不明白的地方

<!DOCTYPE html><html><body><script>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);</script></body></html>    

来源:http://www.w3cschool.cc/js/js-objects.html

有一句不明白呀~为什么要this.changeName=changeName呢?是函数指针的意思么?

记录把方法添加到 JavaScript 对象不明白的地方