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

it2022-05-09  34

<!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呢?是函数指针的意思么?

转载于:https://www.cnblogs.com/jin-wen-xin/p/4022163.html


最新回复(0)