Skip to content

Instantly share code, notes, and snippets.

@paulbaumgart
Created September 22, 2010 21:57
Show Gist options
  • Select an option

  • Save paulbaumgart/592659 to your computer and use it in GitHub Desktop.

Select an option

Save paulbaumgart/592659 to your computer and use it in GitHub Desktop.
var my_eval = eval;
(function() {
var x = 5,
y = 5;
eval("var x = 6");
my_eval("var y = 6");
console.log(x); // 6
console.log(y); // 5
})();
console.log(y); // 6
//console.log(x); // error
@deanlandolt

Copy link
Copy Markdown

heh...i just noticed this yesterday when fixing a narwhal/repl bug...still not quite sure what's going on but var'ing eval gives it its own magical scope

@paulbaumgart

Copy link
Copy Markdown
Author

Yeah, looks like calling any alias to the eval function makes any variables created by eval go into the global scope.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment