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: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]

Reply via email to