Skip to content
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

没有预解析阶段,导致变量不能提升 #6

Open
axetroy opened this issue Mar 5, 2018 · 1 comment
Open

没有预解析阶段,导致变量不能提升 #6

axetroy opened this issue Mar 5, 2018 · 1 comment

Comments

@axetroy
Copy link

axetroy commented Mar 5, 2018

hm....

在实现async await的时候遇到的

变量提升到底是不是个好东西

const obj = {
  called: false
};

func();

function func() {
  obj.called = true;
}

module.exports = obj;

上面的代码是不能解释运行的..

因为解析到func()的时候,还没有func这个变量

@axetroy
Copy link
Author

axetroy commented Mar 5, 2018

我的解决思路是:

在进入新的作用域时,遍历同级节点,把有变量提升作用的节点先处理了

比如var,function。

先定义好变量,再解析

实现中...

@axetroy axetroy changed the title 没有与解析阶段,导致变量不能提升 没有预解析阶段,导致变量不能提升 Mar 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant