Aliased object destructuring assignments?

# Salehen Rahman (9 years ago)

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.

# Sebastian McKenzie (9 years ago)

The syntax is indeed invalid, but syntax does exist to do the equivalent:


var { f: foo } = someObject;

# Edwin Reynoso (9 years ago)
var {f: foo} = {f: 5};
foo == 5 // true
# Salehen Rahman (9 years ago)

Derp. It was right there on the MDN docs. Oh well.

Either ways, thanks for the help! :D