Skip to content

Instantly share code, notes, and snippets.

@thaenor
Last active January 24, 2018 10:19
Show Gist options
  • Save thaenor/d92ee65162104ad20f8844cb45695e3d to your computer and use it in GitHub Desktop.
Save thaenor/d92ee65162104ad20f8844cb45695e3d to your computer and use it in GitHub Desktop.
A Js function to create a function add a set of number - #LIT
function add(x,y) {
var foo = "function customAdd(";
var script = document.createElement('script');
script.setAttribute('type', 'text/javascript');
foo += arguments[0];
for (var i = 1; i < arguments.length; i++){
if(typeof arguments[i] != "number"){
throw new Error("you cheater");
}
foo += "," + arguments[i];
}
foo += "){ return "+ arguments[0];
for (var i = 1; i < arguments.length; i++){
foo += "+" + arguments[i];
}
foo += '); } alert(customAdd());'
console.log(foo);
script.src = foo;
document.getElementsByTagName('head').apendChild(script);
}
add(1,2,3,4,5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment