var example = {
something: 'test',
test: function() {
this.something = 'blah';
}
}
example.test();
在这种情况下,为什么“测试”不会更新为'blah'?
答案 0 :(得分:3)
工作正常。如果您希望example.test()返回新值,请尝试:
var example = {
something: 'test',
test: function() {
this.something = 'blah';
return this.something;
}
}
example.test();
// output: "blah"