Loading ...
Sorry, an error occurred while loading the content.

Invoke a function in an array or object

Expand Messages
  • samckayak
    When an array or object contains functions: var aFunct=[]; aFunct[0]=fnMyFunction; What are the pros and cons of invoking the function using either of the
    Message 1 of 2 , Dec 14, 2009
    • 0 Attachment
      When an array or object contains functions:

      var aFunct=[];
      aFunct[0]=fnMyFunction;

      What are the pros and cons of invoking the function using either of the following:

      aFunct[0]();

      or

      (aFunct[0])();
    • Stefan Weiss
      ... Technically, both versions are correct, but since the parentheses around aFunct[0] are redundant, and there are no ambiguities in aFunct[0](), I can t see
      Message 2 of 2 , Dec 14, 2009
      • 0 Attachment
        On 14/12/09 13:24, samckayak wrote:
        > When an array or object contains functions:
        >
        > var aFunct=[];
        > aFunct[0]=fnMyFunction;
        >
        > What are the pros and cons of invoking the function using either of the following:
        >
        > aFunct[0]();
        >
        > or
        >
        > (aFunct[0])();

        Technically, both versions are correct, but since the parentheses around
        aFunct[0] are redundant, and there are no ambiguities in aFunct[0](), I
        can't see any advantage to the second version.
        Back on topic: JSLint is fine with both.


        regards,
        stefan
      Your message has been successfully submitted and would be delivered to recipients shortly.