【发布时间】:2015-11-14 19:32:29
【问题描述】:
我在理解某一方面有问题。
var Car = function(name, loc) {
'use strict';
this.name = name;
this.loc = loc;
this.methods = {
move: function() {
this.loc++;
},
show: function() {
console.log('Position of ' + this.name + ' is: ' + this.loc);
}
};
};
var amy = new Car('amy', 1);
var ben = new Car('ben', 9);
当我使用 this.loc++ 时,它指的是方法对象,而不是 Car 对象。并且汽车的位置不会增加。我的问题是如何从方法跳转到汽车对象上下文?
【问题讨论】:
标签: javascript object object-oriented-analysis