We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
let name = 2222; let obj = { name: 3333, a: function() { console.log(this.name); // 2222 } } let func = obj.a; func();
这里有问题,func()执行后,打印的是空字符串或undefined(注意:name变量是window对象上的保留变量,所以window.name默认是空字符串),并不是2222。
原因是name是let声明的,因为obj.a赋值给func执行的时候,this指向的是window,而let声明的对象并不存在于window上,所以输出为undefined。除非用var声明,才能达到本例描述的效果。
The text was updated successfully, but these errors were encountered:
哇去,你不说,我还真不知道呢,扑街
Sorry, something went wrong.
No branches or pull requests
这里有问题,func()执行后,打印的是空字符串或undefined(注意:name变量是window对象上的保留变量,所以window.name默认是空字符串),并不是2222。
原因是name是let声明的,因为obj.a赋值给func执行的时候,this指向的是window,而let声明的对象并不存在于window上,所以输出为undefined。除非用var声明,才能达到本例描述的效果。
The text was updated successfully, but these errors were encountered: