调用不带括号的函数 - Invoking a function without parentheses

问题:

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 .我能想到的唯一方法是使用诸如applycall类的函数。

f.apply(this);
f.call(this);

But these require parentheses on apply and call leaving us at square one.但是这些需要括号中的applycall让我们在第一个地方离开。 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 中的函数?


解决方案:

参考一: https://stackoom.com/question/2Qq7W
参考二: Invoking a function without parentheses
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章