I was toying with the number object and I came up with this code (I know this is not good practice):
Number.prototype.times = function (evalString) {
for (let i = 0; i < this; i++) {
eval(evalString);
}
}
//var someVar= 3;
(8).times("alert('kek')");
and it seems to work only when the someVar variable is not mented out, otherwise it throws the error in the title.
What causes this behavior?
I was toying with the number object and I came up with this code (I know this is not good practice):
Number.prototype.times = function (evalString) {
for (let i = 0; i < this; i++) {
eval(evalString);
}
}
//var someVar= 3;
(8).times("alert('kek')");
and it seems to work only when the someVar variable is not mented out, otherwise it throws the error in the title.
What causes this behavior?
Share Improve this question asked Mar 29, 2016 at 7:46 user2151871user2151871 01 Answer
Reset to default 12Placing (...)
immediately after a function expression (function (evalString) { … }
) will call the function with the arguments you specify.
This is why depending on automatic semicolon insertion is not remended. Always end your statements with a ;
.