-
Notifications
You must be signed in to change notification settings - Fork 303
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
How do I create the following chainable functions? #559
Comments
Yes! That is now possible through the use of chainables. |
@andrewplummer That sounds great. I've just spend the better part of an hour trying to figure out the correct Syntax for creating such chainable functions. Can you give an example? Right now my code looks like this:
But when I try to get if the object is true or false, then I get this error:
I know I can do this:
But writing "Sugar.Object" seems a bit long and I can't really use it for much if I don't get back the true/false result. |
You seem to have it set up correctly. When you run Sugar.extend({
objectPrototype: true
}); However this is highly discouraged as it can have lots of unintended consequences. Also, even if you do this your example still will not work as The idea behind chainables is that they are always used through the Sugar global, so If using As for the result, this is intended behavior, so the result can be accessed through the |
Thanks for the thorough explanation. I have 2 last questions:
|
|
To answer your question, though, for now you will need to do either:
or
These are 2 different ways to "unwrap" the resulting chainable. |
Hmm ok. I'll be looking forward to the next version as well. If chainable functions could return true/false values, it would add a lot to the readability of the code IMO. Thanks for the clarification. |
Agreed. Can you also give the proposal a thumbs up? I'm trying to use that to gauge which proposals to focus on for the next version. |
Sure thing. |
I would like to be able to have a more Ruby like syntax, so being able to do the following on the "Object" would be great:
Is it possible to create these chainable functions? How would I do that in Sugar?
The text was updated successfully, but these errors were encountered: