Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for calling GAScriptObject as a function #16

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

b123400
Copy link

@b123400 b123400 commented Feb 5, 2014

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

@newyankeecodeshop
Copy link
Owner

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]

This will allow application to manage when to inject the script. The
current method cannot make sure js is injected before your code runs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants