-
Notifications
You must be signed in to change notification settings - Fork 1.2k
变量作用域,闭包一节的任务,答案错误❌ #1186
New issue
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
Comments
贴个链接 |
+1,我这边试了也是正常 |
@shylock-wu @7ASSEL Hello,这个实际是因为 devtool 默认在非严格模式下,详见 https://zh.javascript.info/strict-mode ![]() 另外,在现代前端开发工具链下,预置开发环境和构建工具基本都会默认开启严格模式。除非显式的通过 @babel/plugin-transform-strict-mode 或者一些配置来放开限制(不建议),非严格模式主要为了向前兼容 ES5 之前的一些表现。 ![]() |
@songhn233 Hi 我测试了一下,在严格模式下,例如在NodeJS中执行这种js文件,是会报错的。但是在Chrome浏览器的控制台执行
|
@shylock-wu 可以试一下重新打开 devtool 后直接执行包含 这是因为截图中其实执行了两次,第一次在非严格模式下,sayHi 已经在全局上下文下被创建了。第二次虽然在严格模式,但 sayHi 在全局可以被找到,alert 就还是正常处理了。每个代码块之间是不会隔离的,需要重启 devtool 来清除副作用。 |
位置
网站实际运行效果
浏览器控制台运行效果
结论
所以我感觉实际上sayHi函数已经被提升了,并且新的词法环境使得两个变量都是能够访问到的
The text was updated successfully, but these errors were encountered: