【发布时间】:2016-04-30 04:26:26
【问题描述】:
为什么这段代码不起作用?我正在尝试使用该方法来添加属性,然后将添加的属性分配给它自己的值。
function howLongILivedSomewhere(college, home1, home2) {
this.birthHome = 18;
this.college = college;
this.home1 = home1;
this.home2 = home2;
this.calcYearsAlive = function() {
return birthHome + college + home1 +home2;
};
this.yearsAlive = calcYearsAlive();
}
var me = new howLongILivedSomewhere(4, 2, 3);
console.log(me);
【问题讨论】:
-
在方法或方法调用中也使用这个关键字
-
@Venkatraman 谢谢!
-
查看我的答案,为您提供解决方案!
标签: javascript object methods