Created
October 27, 2015 19:09
-
-
Save astorm/054eb72f51ac5d87c3fd 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
//calling test1 will **not** define a function you can call in the global scope | |
//functions defined in eval are scoped to the function they're called from | |
function test1() | |
{ | |
eval('function boo(){alert("No one can call me.")}'); | |
} | |
boo(); //boo() is not defined error | |
//calling test2 **will** define a function you can call in the global scope | |
//the window object and the global scope are the same things in javascript | |
function test(){ | |
eval('window.boo = function (){alert("Boo! Did I scare you?")}'); | |
}; | |
boo(); //alert window will show |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment