Skip to content

Assign properties from object #3225

@solova

Description

@solova

Docs contains good example:

class Person
  constructor: (options) -> 
    {@name, @age, @height} = options

It's short and clear.
When I want to assign variables from object to locat variables it's work too:

{_name, _age, _height} = options

But If I want assign variables from one object to another I get error:

{obj.name, obj.age, obj.height} = options

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:

{$scope.prevPage, $scope.nextPage} = response

Of couse I can use parallel assignment:

[$scope.prevPage, $scope.nextPage] = [response.prevPage, response.nextPage]

but it's longest and produced redundancy code.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions