【发布时间】:2016-12-20 17:09:45
【问题描述】:
我有这个:
function Person(number){
this.number = number;
}
Person.prototype.wording = function(){
if (this.person == 1){
return "person is";
} else {
return "people are";
}
};
var per1 = new Person(1);
console.log(per1.wording, '**');
我退出了[Function]
当我在我的实例上调用它时,如何将方法绑定到对象或告诉它运行该函数
【问题讨论】:
-
wording是一个函数,只需使用per1.wording()调用它。另外,请记住this.person将始终为undefined(至少使用当前代码),也许您的意思是this.number? -
哦。我可能误解了 is/are。新人(5);//对我来说毫无意义
-
@haim770 这对我来说很特别:/。谢谢!
标签: javascript object methods