invoking a function with variable number of arguments

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts

  • Thomas 'PointedEars' Lahn
    Guest replied
    Re: invoking a function with variable number of arguments

    RobG wrote:
    On Jun 17, 7:55 am, laredotornado <laredotorn...@ zipmail.comwrot e:
    >I'm passing a function, "myFunc" as an argument to another function,
    >"doFunc". In "doFunc", I am creating an arbitrary number of arguments
    >to pass to "myFunc". How do I invoke "myFunc" with an arguments array
    >stored in "argsArr"? Here is the basic function skeleton:
    >>
    >function doFunc(myFunc) {
    > var argsArr = getArgsArray();
    > // invoke myFunc with argsArr ... how?
    >
    Use Function.protot ype.apply:
    >
    myFunc.apply(wi ndow, argsArr);
    Needlessly proprietary and error-prone. Should be

    myFunc.apply(th is, argsArr);

    in global context and

    myFunc.apply(gl obal, argsArr);

    in local context with `global' assigned as

    var global = this;

    in global context before.


    PointedEars
    --
    var bugRiddenCrashP ronePieceOfJunk = (
    navigator.userA gent.indexOf('M SIE 5') != -1
    && navigator.userA gent.indexOf('M ac') != -1
    ) // Plone, register_functi on.js:16

    Leave a comment:


  • RobG
    Guest replied
    Re: invoking a function with variable number of arguments

    On Jun 17, 7:55 am, laredotornado <laredotorn...@ zipmail.comwrot e:
    Hi,
    >
    I'm passing a function, "myFunc" as an argument to another function,
    "doFunc". In "doFunc", I am creating an arbitrary number of arguments
    to pass to "myFunc". How do I invoke "myFunc" with an arguments array
    stored in "argsArr"? Here is the basic function skeleton:
    >
    function doFunc(myFunc) {
    var argsArr = getArgsArray();
    // invoke myFunc with argsArr ... how?
    Use Function.protot ype.apply:

    myFunc.apply(wi ndow, argsArr);


    <URL: http://developer.mozilla.org/en/docs...Function:apply
    >
    >
    }

    --
    Rob

    Leave a comment:


  • VK
    Guest replied
    Re: invoking a function with variable number of arguments

    On Jun 17, 1:55 am, laredotornado <laredotorn...@ zipmail.comwrot e:
    Hi,
    >
    I'm passing a function, "myFunc" as an argument to another function,
    "doFunc". In "doFunc", I am creating an arbitrary number of arguments
    to pass to "myFunc". How do I invoke "myFunc" with an arguments array
    stored in "argsArr"? Here is the basic function skeleton:
    >
    function doFunc(myFunc) {
    var argsArr = getArgsArray();
    // invoke myFunc with argsArr ... how?
    >
    }
    function doFunc(myFunc) {
    myFunc.apply(nu ll,getArgsArray ());
    }

    function getArgsArray() {
    return [1,2,3];
    }

    function f() {
    for (var i=0; i<arguments.len gth; i++) {
    window.alert(ar guments[i]);
    }
    }

    doFunc(f);

    Leave a comment:


  • laredotornado
    Guest started a topic invoking a function with variable number of arguments

    invoking a function with variable number of arguments

    Hi,

    I'm passing a function, "myFunc" as an argument to another function,
    "doFunc". In "doFunc", I am creating an arbitrary number of arguments
    to pass to "myFunc". How do I invoke "myFunc" with an arguments array
    stored in "argsArr"? Here is the basic function skeleton:

    function doFunc(myFunc) {
    var argsArr = getArgsArray();
    // invoke myFunc with argsArr ... how?
    }

    Thanks for the help, - Dave
Working...