当我在node.js中输入这个时,我得到了
undefined
。var testContext = 15;
function testFunction() {
console.log(this.testContext);
}
testFunction();
=>undefined
没有使用 var
关键字,它通过了(=>15)。在 Chrome 控制台中可以工作并且可以使用或不使用 var
关键字。
console.log()
时删除this.
吗? - Justin Niessnerthis.
后可以正常工作。为什么?如果在另一个 node.js 文件中调用了testFunction();
,它是否仍然有效?(已测试是的,但为什么?) - Weishi Z