-
Notifications
You must be signed in to change notification settings - Fork 2k
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
reconstruction feature #1617
Comments
+1 |
To fix this in the near-term, you could do something like this:
|
That's funny. I was thinking about this exact same thing about an hour ago. I was thinking of extending the underscore extend function. If a param on the right was an array it would use the first item as the object and the rest as allowed property names. This way you could have multiple docs on the right as _.extend normally does.
|
That's good, too. I'm glad I came across this. I hadn't thought much of "selective mixins" until I read over your problem. This would be a great CS feature. |
I just put this in my production code ...
|
|
I second this. I often do things like:
I would love to be able to shorten it to:
Concise and clear, IMO. The coco syntax is almost better, though. No extraneous variables. |
I'm fond of that coco syntax as well. edit: I mean, with the |
Inevitable as long as we have implicit call:
Avoiding it by using longhand is possible though:
|
Yeah, the Coco syntax
is really nice. Provides DRY for a very common use case. I'd expect rave reviews if it were added in 1.2. |
That would just expand into:
? |
@cpryland No, try it out in the Coco console: http://satyr.github.com/cup/ You can write
and that last line is equivalent to
and So, it's a nicely symmetric form of the |
#1632 is slightly related |
#1708 is much more related |
@accelware but it's using the curlies! If we had a similar syntax for returning an array of multiple properties, I'd expect it to use square brackets.
As it turns out, coco has this feature as well and I really like it. |
I recently tried:
And was disappointed when it didn't do what I expected, which was to create |
@michaelficarra I sure would. In fact, I thought I had commented on that issue saying as much, but it seems I must have 👍ed that syntax in another, related issue. 8| |
@michaelficarra I didn't mean to state a syntax preference. Only noting that I'd been hoping for a way to do hash slicing. |
+1 fo' sho'! |
i suggested this a while ago, for use of something like
for now, I've been using
|
I like the It is very confusing how |
Closing this request as it’s not a priority at the moment. That said, if someone feels like implementing this as a PR that doesn’t introduce any breaking changes, it would be considered. |
I have asked for this before but I have now run into about a dozen places in my app where I have code like this (production code) ...
... and I would really like to shorten it to ...
This allows one to select a subset of an object to create a new object. I do this all the time. In this particular example it is doing deconstruction and then reconstruction in one operation.
I don't really care what the syntax is, I just don't want to repeat the source object over and over. Another syntax option would be something like this (just replace the right = with "in") ...
The token "in" could be any token/operator that doesn't break the language. The token means "use the following as the default object for this constructor instead of the local scope".
Each time I write code like this I pine for the feature more and more. How hard would it be to add this feature? I would be willing to spend whatever time it takes to code this for a pull request.
The text was updated successfully, but these errors were encountered: