var example = {
something: 'test',
test: function() {
this.something = 'blah';
}
}
example.test();
在这种情况下,为什么“test”没有更新为“blah”?
最佳答案
效果很好。如果您希望 example.test() 返回新值,请尝试以下操作:
var example = {
something: 'test',
test: function() {
this.something = 'blah';
return this.something;
}
}
example.test();
// output: "blah"
关于JavaScript 分配变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14730661/