I was told today that it's possible to invoke a function without parentheses.(今天我被告知可以调用没有括号的函数。)
The only ways I could think of was using functions like apply
or call
.(我能想到的唯一方法是使用apply
或call
类的功能。)
f.apply(this);
f.call(this);
But these require parentheses on apply
and call
leaving us at square one.(但这些要求括号apply
并call
我们留在第一方。) I also considered the idea of passing the function to some sort of event handler such as setTimeout
:(我还考虑了将函数传递给某种事件处理程序(如setTimeout
的想法:)
setTimeout(f, 500);
But then the question becomes "how do you invoke setTimeout
without parentheses?"(但问题就变成了“如何在没有括号的情况下调用setTimeout
?”)
So what's the solution to this riddle?(那么这个谜语的解决方案是什么?) How can you invoke a function in Javascript without using parentheses?(如何在不使用括号的情况下在Javascript中调用函数?)
ask by Mike Cluck translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…