ccgus / CocoaScript

JavaScript + the Cocoa frameworks, and then ObjC brackets show up to party as well.
Other
618 stars 58 forks source link

How to go from Objective-C-style to normal JS declarations? #49

Closed sdaitzman closed 7 years ago

sdaitzman commented 7 years ago

For example: how would I go from [fill setColor:[MSImmutableColor colorWithSVGString: colors[r]]]; to the equivalent in JS property syntax (dot-notation)?

Thank you so much for the help.

ccgus commented 7 years ago

Did you try what you've got above? CocoaScript lets you use brackets.

sdaitzman commented 7 years ago

@ccgus thank you for your prompt response!

I prefer the dot-notation syntax for this project, and I am using a build tool that will not work without formatting that way. I've been unable to find any reliable guidelines for how to go from the Objective-C bracket syntax to dot notation.

ccgus commented 7 years ago

You can replace objc's :'s with _'s. Using CocoaScript Editor's pre processor, it'll turn the above into this:

fill.setColor_( MSImmutableColor.colorWithSVGString_( colors[r]));

If there are multiple arguments to a method, then you'd do this:

[f call:a whatever:b];

f.call_whatever_(a, b)
sdaitzman commented 7 years ago

@ccgus thank you! This is very helpful.