Skip to content

Instantly share code, notes, and snippets.

@masahitojp
Created January 31, 2011 05:22
Show Gist options
  • Save masahitojp/803672 to your computer and use it in GitHub Desktop.
Save masahitojp/803672 to your computer and use it in GitHub Desktop.
"new Function" is different from eval
var a = 1;
(function(num){
var a = 10;
// function literal
//var f = function(b){return a + b;};
// eval
//eval("var f = function(b){return a + b;}");
// Function object
//var f = new Function("b","return a + b;");
return f(num);
}
)(100);
// function literal 110
// eval 110
// Function Object 101 <= window.aを参照してる
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment