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
var scope = "global scope"; function checkscope(){ var scope = "local scope"; function f(){ return scope; } return f; } checkscope()();
这端代码输出的答案是:local scope;为什么呢? 执行过程伪代码:
- [全局]EC - [local scope]EC - [f]EC f函数执行能访问到local scope,所以输出local scope
- [全局]EC - [local scope]EC - 闭包 执行到闭包时,[local scope]EC已出栈,所以闭包内this指向window,但是我们知道闭包能访问上层变量,也就是[local scope]EC里的变量,所以打印出来的也是local scope
The text was updated successfully, but these errors were encountered:
// f1 console.log(func1) // Uncaught ReferenceError: func1 is not defined func1 = function() { console.log(1) }
// f2 console.log(func2) // undefined var func2 = function() { console.log(1) }
// f3 console.log(func3) // func3函数 function func3() { console.log(1) }
参考这篇文章的时候想起的小问题
Sorry, something went wrong.
No branches or pull requests
第1题
这端代码输出的答案是:local scope;为什么呢?
执行过程伪代码:
第2题
这端代码输出的答案是:local scope;为什么呢?
执行过程伪代码:
The text was updated successfully, but these errors were encountered: