Skip to content

Instantly share code, notes, and snippets.

@guillermoroblesjr
Created April 30, 2015 15:58
Show Gist options
  • Save guillermoroblesjr/0e7881125ac74d0e573f to your computer and use it in GitHub Desktop.
Save guillermoroblesjr/0e7881125ac74d0e573f to your computer and use it in GitHub Desktop.
Create a JavaScript function dynamically with strings
// Create the function
// 'a' and 'b' are the arguments available to the function,
// the last string is the body of your new function
var x = Function('a','b','console.log(a+b); return "apples";');
// Implementation
x(1,2); // will return 'apples' and will log to the console '3';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment