GAJavaScript
GAJavaScript copied to clipboard
Added support for calling GAScriptObject as a function
"callFunction" only allows a function to be called if it is a property of an object. "callAsFunction" allows functions to be called directly, which is more flexible.
One good application would be using callback to handle the no-return-value problem.
-(void)getValueWithCallback:(GAScriptObject*)callback{
[callback callAsFunctionWithArguments:@[@"Hello"]];
}
GAJavaScript.performSelector( 'getValueWithCallback:', function(value){
// value == "Hello"
});
This is a good idea. Since functions are objects though, you could invoke the function by using the "call" or "apply" method? [GAScriptObject callFunction:@"apply" withObject:arrayOfArgs]