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

Arguments: why not hashes/dictionaries? #15

Closed
aseemk opened this issue May 18, 2012 · 2 comments
Closed

Arguments: why not hashes/dictionaries? #15

aseemk opened this issue May 18, 2012 · 2 comments

Comments

@aseemk
Copy link

aseemk commented May 18, 2012

Very cool stuff!

Sorry, this is more of a question than an issue, but didn't know where else to ask:

In Objective-C, the names of methods are part of the arguments that you pass
along:

[array insertObject:obj atIndex:5];

The equivalent of the above message invocation in NodObjC syntax would be:

array('insertObject', obj, 'atIndex', 5)

So the even numbered arguments are the parts of the method name that will be
invoked, and the odd numbered arguments are the Obj-C arguments themselves. In
the above example, the insertObject:atIndex: function will be invoked.

How come these arguments aren't just passed as a dictionary instead?

array({
  insertObject: obj,
  atIndex: 5,
});

I'm an Obj-C noob, so apologies if there's an obvious answer and I'm missing it. =)

Great stuff again!

@TooTallNate
Copy link
Owner

Actually, both of these syntaxes are supported, just the varargs format is "preferred" because of consistency. Consider a method that does not accept any arguments, you could not represent that using an Object, so a String is the only thing we can do:

obj({ method: ??? })  // bad
obj('method')  // good

But actually, both of these will work:

obj({ method: arg })
obj('method', arg)

So really, just use whatever you prefer :)

@aseemk
Copy link
Author

aseemk commented May 20, 2012

Cool, thanks. =)

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

No branches or pull requests

2 participants