Aliased object destructuring assignments?
# Sebastian McKenzie (9 years ago)
The syntax is indeed invalid, but syntax does exist to do the equivalent:
var { f: foo } = someObject;
The syntax is indeed invalid, but syntax does exist to do the equivalent: ```javascript var { f: foo } = someObject; ``` On Mon, Jun 22, 2015 at 1:50 AM, Salehen Rahman <salehen.rahman at gmail.com> wrote: > I know that `import` allows us to alias imports, like so: > ```javascript > import { f as foo } from 'f'; > ``` > But what about object destructuring assignments? > ```javascript > var { f as foo } = someObject; // Syntax error on Babel > ``` > Either Babel is very late in the game, or the above syntax is actually not > supported in ECMAScript. > It would be really beneficial to support aliasing for object destructuring. > I find it would make sense since array destructuring assignments allow us > to assign values to arbitrary variable names. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150621/c324dde6/attachment-0001.html>
# Edwin Reynoso (9 years ago)
var {f: foo} = {f: 5};
foo == 5 // true
```JS var {f: foo} = {f: 5}; foo == 5 // true ``` On Sun, Jun 21, 2015 at 8:50 PM, Salehen Rahman <salehen.rahman at gmail.com> wrote: > I know that `import` allows us to alias imports, like so: > > ```javascript > import { f as foo } from 'f'; > ``` > > But what about object destructuring assignments? > > ```javascript > var { f as foo } = someObject; // Syntax error on Babel > ``` > > Either Babel is very late in the game, or the above syntax is actually not > supported in ECMAScript. > > It would be really beneficial to support aliasing for object destructuring. > > I find it would make sense since array destructuring assignments allow us > to assign values to arbitrary variable names. > > > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150621/7273cbd7/attachment.html>
# Salehen Rahman (9 years ago)
Derp. It was right there on the MDN docs. Oh well.
Either ways, thanks for the help! :D
Derp. It was right there on the MDN docs. Oh well. Either ways, thanks for the help! :D On Sun, Jun 21, 2015 at 5:55 PM, Edwin Reynoso <eorroe at gmail.com> wrote: > ```JS > var {f: foo} = {f: 5}; > foo == 5 // true > ``` > > On Sun, Jun 21, 2015 at 8:50 PM, Salehen Rahman <salehen.rahman at gmail.com> > wrote: > >> I know that `import` allows us to alias imports, like so: >> >> ```javascript >> import { f as foo } from 'f'; >> ``` >> >> But what about object destructuring assignments? >> >> ```javascript >> var { f as foo } = someObject; // Syntax error on Babel >> ``` >> >> Either Babel is very late in the game, or the above syntax is actually >> not supported in ECMAScript. >> >> It would be really beneficial to support aliasing for object >> destructuring. >> >> I find it would make sense since array destructuring assignments allow us >> to assign values to arbitrary variable names. >> >> >> >> _______________________________________________ >> es-discuss mailing list >> es-discuss at mozilla.org >> https://mail.mozilla.org/listinfo/es-discuss >> >> > -- shovon.github.io @shovnr <http://twitter.com/shovnr> -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150621/0f631bd6/attachment.html>
I know that
import
allows us to alias imports, like so:import { f as foo } from 'f';
But what about object destructuring assignments?
var { f as foo } = someObject; // Syntax error on Babel
Either Babel is very late in the game, or the above syntax is actually not supported in ECMAScript.
It would be really beneficial to support aliasing for object destructuring.
I find it would make sense since array destructuring assignments allow us to assign values to arbitrary variable names.