Last active
November 5, 2017 02:20
-
-
Save DmitrySoshnikov/e7e57fe12b47b67b89227b9326f1bfbf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* JavaScript runtime-augmented scope example. | |
*/ | |
let x = 10; | |
let o = {x: 30}; | |
let storage = {}; | |
(function foo(flag) { | |
if (flag == 2) { | |
eval("var x = 20;"); | |
} | |
if (flag == 3) { | |
storage = o; | |
} | |
with (storage) { | |
// "x" may be resolved either | |
// in the global scope - 10, or | |
// in the local scope of a function - 20 | |
// (created via "eval" function), or even | |
// in the "storage" object - 30 | |
console.log(x); // ? - scope of "x" is undetermined at compile time | |
} | |
// organize recursion on 3 calls | |
if (flag < 3) { | |
foo(++flag); | |
} | |
})(1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment