"Take props" from object

# Dmitry Soshnikov (9 years ago)

Hey guys,

From an internal conversation, we've received a question, and as a follow

up, the proposal of "take needed props from an object".

Currently if you need to take some properties from an object, you'd do:

var foo = {x: bar.x, y: bar.y, z: bar.z};

With possible shorthand it even could be (I guess someone proposed this already at some point):

var foo = {bar.x, bar.y, bar.z};

Sometimes one could also do with destructuring and shorhands, but these are two actions

var {x, y, z} = bar;
var foo = {x, y, z};

And the "take props" operator combine those approaches, and may look like an import statement from a module, just without the import keyword:

var foo = {x, y, z} from bar;

I personally liked this strawman, it smoothes the border between a module and an object (which is also a module/namespace, from which we can "import" needed "exports").

I haven't checked yet the grammar, seems should be fine from the first glance.

Thoughts?

Dmitry

# Dmitry Soshnikov (9 years ago)

On Wed, Aug 19, 2015 at 9:22 PM, Dmitry Soshnikov < dmitry.soshnikov at gmail.com> wrote:

var foo = {x, y, z} from bar;

I haven't checked yet the grammar, seems should be fine from the first glance.

Yeah, it should be parsed first as an object literal, and then to the "take props" operator if the lookahead is from.

Dmitry