Skip to content

Object interpolation #1864

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
curvedmark opened this issue Nov 13, 2011 · 1 comment
Closed

Object interpolation #1864

curvedmark opened this issue Nov 13, 2011 · 1 comment

Comments

@curvedmark
Copy link

Can we support this kind of syntax:

obj =
    b: 2
{
    a: 1
    obj
    c: 2
}

which will be compiled into something like this:

var _extend = function () { //... }
var obj = { b: 2 };
_extend({ a:1 }, obj, { c:2 });

Nested version:

obj1 =
    b: 2
obj2 =
    e: 5
{
    a: 1
    obj1
    c:
        d: 4
        obj2
}

which will be compiled into:

var _extend = function () { //... }
var obj1 = { b: 2 }, obj2 = { e:5 };
_extend({ a:1 }, obj, { c: _extend({d: 4}, obj2) });

obj doesn't have to be a variable, it can also be a literal (array, object, etc). Is this idea feasible?

I see CS currently compiles this

fn
    a:1
    obj
    b:2

into this

fn({
  a: 1
}, obj, {
  b: 2
});

I'm not sure if it's OK to break this compatibility, but I think it would be really cool if we could "interpolate" into object literals

@michaelficarra
Copy link
Collaborator

Duplicate of #1632

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants