var name = "Richard";
function not(f) {
return function() {
console.log("This: " + this);
var result = f.apply(this);
return result;
};
}
function test () {
var name = "Rob";
console.log("Result: " + this.name);
return this.name; // Richard (not Rob, because "this" refers to the window object, and it uses the name variable from the global window object)
}
var news = not (test);
news ();
以上是我试图通过以下网站了解的代码:http://javascriptissexy.com/understand-javascript-callback-functions-and-use-them/
这里作者提到输出应该是"结果:Richard",但是控制台输出是"结果:结果"
请解释出现差异的原因。提前谢谢。