如何扩展此范围以便下面的工作?我试过使用.bind()函数,但我似乎无法得到任何工作。如何扩展此范围
var myObj = {
test: "Hello",
test2: " World",
run: {
all: function() {
return this.test + this.test2;
},
part: function() {
return this.test2;
}
}
}
console.log(myObj.run.all())
// => "Hello World"
console.log(myObj.run.part())
// => " World"
你必须明白:'this'在你的职责是当前对象,这就是你要的影响'run',而不是超对象。在run(和'this' btw)中,只有'all()'和'part()',没有'test'和'test2'。 – sjahan