Question:
what is a javascript function call with 2 sets of parentheses mean?
tohmaI
2009-06-13 02:08:46 UTC
I saw this code and could not make out why there are double parenthese in this chained javascript call (example):

obj1.obj2.functionX (o, values, _action) (onTaskAComplete, onTaskBError);

I can see the call to functionX of obj2 in obj2.functionX(o, values, _action), but what is the next set of arguments within the next parentheses for? I.e. (onTaskAComplete, onTaskBError)? Which object or function do this parameters belong to in this chain?

Thanks for help.
Three answers:
richarduie
2009-06-13 06:29:18 UTC
Most likely obj1.obj2.functionX( ) returns a reference to a function based on the values of its arguments (o, values, _action). The function returned from that call takes the arguments (onTaskAComplete, onTaskBError) which are references to two other functions. The returns from the functionX( ) call need references for the complete and error functions (probably event handlers in the application space) and call one or the other based on the state of the system. Another possibility is that a function returned by the call to functionX( ) may attach the complete and error functions to events or other objects, rather than actually calling the functions directly. There are many potential levels of indirection of execution when passing function references.



In JavaScript, Function is an Object. Thus, functions can be referenced by names either directly or indirectly. Functions can exist as stand-alone elements or as properties of other objects according to the closures within which they are declared. Functions can also be passed by reference, using the name of the object (function). Here's a couple of simple examples that should help you to understand the double parentheses notation and the idea of passing functions by reference.















?
2016-10-18 14:15:12 UTC
Javascript Parentheses
SANCHIT ABROL
2009-06-13 02:15:40 UTC
ontaskcmoplete specifies what to do when task complete

second is the errorhandler


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...