最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - TypeError: (intermediate value)(...) is undefined - Stack Overflow

programmeradmin3浏览0评论

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 0
Add a ment  | 

1 Answer 1

Reset to default 12

Placing (...) 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 ;.

发布评论

评论列表(0)

  1. 暂无评论