Hi,
I have a constructor function for my hypothetical "Contact" class that looks like this.
class Contact {
...
constructor(contactDetails) { // contactDetails is an object
this.name = contactDetails.name;
this.contact = contactDetails.contact;
this.IM = contactDetails.IM;
}
...
};
Wouldn't it be nice to have a syntactic sugar allowing us to destructure contactDetails properties and binding to this in one line as below
class Contact {
...
constructor(contactDetails) { // contactDetails is an object
this.{name, contact, IM} = contactDetails;
}
...
};
For constructor parameters passed as arrays
Hi,
I have a constructor function for my hypothetical "Contact" class that looks like this.
class Contact {
...
constructor(contactDetails) { // contactDetails is an object {}
this.name = contactDetails.name;
this.contact = contactDetails.contact;
this.IM = contactDetails.IM;
}
...
};
Wouldn't it be nice to have a syntactic sugar allowing us to destructure contactDetails properties and binding to this in one line as below
class Contact {
...
constructor(contactDetails) { // contactDetails is an Array []
this.[name, contact, IM] = contactDetails;
}
...
};
(In reply to comment #0)
> Hi,
>
> I have a constructor function for my hypothetical "Contact" class that looks
> like this.
>
> class Contact {
> ...
> constructor(contactDetails) { // contactDetails is an object
> this.name = contactDetails.name;
> this.contact = contactDetails.contact;
> this.IM = contactDetails.IM;
> }
> ...
> };
>
> Wouldn't it be nice to have a syntactic sugar allowing us to destructure
> contactDetails properties and binding to this in one line as below
>
> class Contact {
> ...
> constructor(contactDetails) { // contactDetails is an object
> this.{name, contact, IM} = contactDetails;
> }
> ...
> };
>
> For constructor parameters passed as arrays
>
> Hi,
>
> I have a constructor function for my hypothetical "Contact" class that looks
> like this.
>
> class Contact {
> ...
> constructor(contactDetails) { // contactDetails is an object {}
> this.name = contactDetails.name;
> this.contact = contactDetails.contact;
> this.IM = contactDetails.IM;
> }
> ...
> };
>
> Wouldn't it be nice to have a syntactic sugar allowing us to destructure
> contactDetails properties and binding to this in one line as below
>
> class Contact {
> ...
> constructor(contactDetails) { // contactDetails is an Array []
> this.[name, contact, IM] = contactDetails;
> }
> ...
> };
Sorry there was a copy paste error in my last post Kindly ignore the last post as I am editing and pasting it here again.
-----------------------------------------------------------------------------
Hi,
I have a constructor function for my hypothetical "Contact" class that looks
like this.
class Contact {
...
constructor(contactDetails) { // contactDetails is an object
this.name = contactDetails.name;
this.contact = contactDetails.contact;
this.IM = contactDetails.IM;
}
...
};
Wouldn't it be nice to have a syntactic sugar allowing us to destructure
contactDetails properties and binding to this in one line as below
class Contact {
...
constructor(contactDetails) { // contactDetails is an object {}
this.{name, contact, IM} = contactDetails;
}
...
};
For constructor parameters passed as arrays
class Contact {
...
constructor(contactDetails) { // contactDetails is an Array []
this.[name, contact, IM] = contactDetails;
}
...
};
using features already in ES6 spec.:
class Contact {
...
constructor(contactDetails) { // contactDetails is an object
let {name, contact, IM} = contactDetails; //ensure props present
Object.assign(this, {name, contact, IM});
}
...
};
Bulk closing all Harmony bugs. Proposals should be tracked on GitHub. The ES wiki is completely defunct at this point.