Function reference arguments in json format (actually, object literal)
Is it possible add an argument to a f开发者_运维问答unction reference in an object literal:
var custom = {onLoadBegin: onLoadBegin};
Would like it to be
onLoadBegin('argument')
Assuming you have a function named onLoadBegin
that is external to custom
, then you could do this:
var custom = {
onLoadBegin: function() {
onLoadBegin("argument");
}
};
When you call custom.onLoadBegin
it will invoke the original onLoadBegin
with your argument.
Yes, in your example you could call custom.onLoadBegin(argument)
You need to put your handler in a closure:
var loadHandler = function() {
doSomething('argument');
}
onLoadBegin( loadHandler );
You can also do this with an anonymous function:
onLoadBegin( function() {
doSomething('argument');
});
the JSON format does not include functions, it's just for data. Please provide extra information about what exactly you want to achieve
If you don't care about the standard and you just want to get stuff done, you can do it like this:
{functionName: [argument1, argument2, ...]}
And on the client side, do something like this:
window[key].apply(this, value)
精彩评论