cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Oliver <res1c...@verizon.net>
Subject Re: [Proposal] Implementing XMLForm with Flow
Date Mon, 23 Dec 2002 19:05:41 GMT

Ugo Cei wrote:

> Christopher Oliver wrote:
>
>> Try this:
>>
>> function checkLogin(funarg) {
>>      if (user == null) {
>>           login();
>>           this[funarg]();
>>      }
>> }
>
>
> Thanks, it worked! While you're at it, would it be possible to pass 
> arguments to "funarg", by defining them in the sitemap? I mean:
>
>         <map:call function="checkLogin">
>           <map:parameter name="funarg" value="protected"/>
>           <map:parameter name="arg1" value="somevalue"/>
>           <map:parameter name="arg2" value="someothervalue"/>
>         </map:call>
>
>  function checkLogin(funarg, ???) {
>       if (user == null) {
>            login();
>            this[funarg](???);
>       }
>  }
>
> What should I put in place of the question marks? Assume that the 
> number of arguments is variable. Pardon my Javascript ignorance and 
> thanks again ;-).
>
>     Ugo

Yes, you can use Function.apply() to pass a variable argument list to 
another function,  like this:

function checkLogin(funArg) {
        if (user == null) {
              login();
        }
       // In JavaScript, the magic variable "arguments" contains the 
actual list of arguments passed to a function.
       // Arguments supports a "length" property, and array indexing.
       var newArgs = new Array(arguments.length-1);
       for (var i = 1; i < arguments.length; i++) {
              newArgs[i-1] = arguments[i];
       }
       var fun = this[funArg];
       fun.apply(this, newArgs);
}


---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org


Mime
View raw message