vertti vertti - 1 year ago 80
Javascript Question

Nested call to function in Javascript

Intellij IDEA shows a warning when ever I write Javascript like this:


But the explanation is not really helpful:

"This inspection reports any Javascript function calls used as
arguments to another function call."

This is something I do frequently, so what's the potential trap hiding there worth warning of? Or if it's just some coding convention, what's the reason for it?

Answer Source

It is a warning because most of the time, you want to pass a function reference as an argument. It is mostly used as a callback:


In that example, someOtherFunction() instead of someOtherFunction would not work as expect (unless someOtherFunction returns a function itself).

someFunction(someOtherFunction()); work more like a getter.

    alert(int === 1);//True;
    return 1;

It gives a warning because it is a common mistake for new developers.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download