function Person(name){
this.name = name;
}
Person.prototype.greet = function(otherName){
return "Hi " + otherName + ", my name is " + name;
}
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
这跟继承没得关系,
greet
是原型方法,Person
对象可以使用的,但是里面对name
的引用错了,需要加this.
。