TypeError :(中间值)(...)未定义 [英] TypeError: (intermediate value)(...) is undefined
本文介绍了TypeError :(中间值)(...)未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在玩弄数字对象,我想出了这个代码(我知道这不是一个好习惯):
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')");
它似乎仅在someVar变量没有被注释掉时才起作用,否则它会抛出错误标题。
and it seems to work only when the someVar variable is not commented out, otherwise it throws the error in the title.
导致这种行为的原因是什么?
What causes this behavior?
推荐答案
放置(...)
在函数表达式( function(evalString){...}
)之后立即调用具有您指定的参数的函数。
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 recommended. Always end your statements with a ;
.
这篇关于TypeError :(中间值)(...)未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文