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

ReferenceError on a valid code. #18

Open
w32zhong opened this issue Jan 2, 2018 · 1 comment
Open

ReferenceError on a valid code. #18

w32zhong opened this issue Jan 2, 2018 · 1 comment

Comments

@w32zhong
Copy link

w32zhong commented Jan 2, 2018

var result = [];
for (var i=0; i<2; i++) {
    (function () {
        var copy = i;
        var func = function () {
            return copy;
        };
        result.push(func);
    }());
}

console.log(result[0]());

Flat will report Reference error while node engine does not:

$ ./flathead/bin/flat ./test.js 
ReferenceError: copy is not defined
  at ./test.js:6:10
  at (anonymous function) in ./test.js:12:22
$ node ./test.js 
0
@ndreynolds
Copy link
Owner

Thanks for the bug report! Seems like a bug in how the anonymous function's scope is set up. I'll make a test case out of this and try to come up with a fix.

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

2 participants