GAJavaScript icon indicating copy to clipboard operation
GAJavaScript copied to clipboard

Added support for calling GAScriptObject as a function

Open b123400 opened this issue 11 years ago • 1 comments

"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"
});

b123400 avatar Feb 05 '14 09:02 b123400

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]

newyankeecodeshop avatar Feb 07 '14 21:02 newyankeecodeshop