1.在vscode中运行以下代码显示错误:window is not defined。一直没想明白到底哪里有错,最后发现是自己的运行环境是node.js.window是web浏览器中才有的对象。所以在浏览器中运行以下代码就能正确显示。还包括以下情况
window.color = ‘red‘; let o = { color : ‘blue‘ } let sayColor = function() {console.log(this.color);} sayColor(); o.sayColor = sayColor; o.sayColor();
2.
let color = ‘red‘; let o = { color : ‘blue‘ } let sayColor = function() {console.log(this.color);} sayColor();//undefined o.sayColor = sayColor; o.sayColor();//blue