Skip to content

Instantly share code, notes, and snippets.

@astorm
Created October 27, 2015 19:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save astorm/054eb72f51ac5d87c3fd to your computer and use it in GitHub Desktop.
Save astorm/054eb72f51ac5d87c3fd to your computer and use it in GitHub Desktop.
//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