-
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
Assign properties from object #3225
Comments
This is where LiveScript becomes a very handy alternative 😉 : obj <<< options{name, age, height} compiles to: obj.name = options.name;
obj.age = options.age;
obj.height = options.height; |
Another LiveScript alternative (that i find a bit more intuitive): obj{name, age, height} = options |
Of course @epidemian, you're right, I just forgot about this form! ^^ And this is perfectly matching the semantics of what @xelios20 wants. |
for methods / function it can looks like
but have solution like:
would be nice |
I think that this is an extension worth having, if anyone wants to take a stab at it. The general idea would be to take the current destructuring assignment, and then allow it to be prefixed:
Note that there will be some tricky bits for compilation, that would need to be cached:
But now that I'm writing that above example ... it also seems like the potential for totally garbled and hard to parse syntax here is pretty high. Do folks think this is useful enough to add? Or potentially way too complicated to read to be worth having? |
I really like it in LS. most useful with |
From #1952 thread: {prevPage: $scope.prevPage, nextPage: $scope.nextPage} = response # works now
$scope{prevPage, nextPage} = response # should work
{prevPage: $scope.a, nextPage: $scope.b} = response # works now
$scope{prevPage: a, nextPage: b} = response # should work |
Oh my goodness, |
+1 |
+1 |
If someone wants to implement this, a pull request would be welcome. |
Docs contains good example:
It's short and clear.
When I want to assign variables from object to locat variables it's work too:
But If I want assign variables from one object to another I get error:
I think It's not issue. But this fall short of expectations.
I suggest to add this functionality. I'm pretty much sure it's very useful.
For example in Angular:
Of couse I can use parallel assignment:
but it's longest and produced redundancy code.
The text was updated successfully, but these errors were encountered: