Last active
January 24, 2018 10:19
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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