JavaScript object notation shorthand

I saw this syntax in JavaScript and thought it might be some feature from TypeScript or some other higher level layer:

let text = "Hello World"
let state = { fruit: "banana" }

let obj = { text, state }

But it turns out in plain JavaScript that now does the same thing as:

let obj = { text: "Hello World", state: { fruit: "banana" } }

In fact they also have "computed property names":

let prop = 'foo';
let o = {
    [prop]: 'hey',
    ['b' + 'ar']: 'there'
}

Object initializer - JavaScript | MDN

Ren-C is inches away from doing the computed property names in MAKE OBJECT! (using SET-GROUP! rather than SET-BLOCK! would be more appropriate).

But because of the freeform nature of the code block in MAKE OBJECT!, the appearance of a WORD! alone can't indicate an embedded field.

It may be that there should be a less freeform alternative to MAKE OBJECT! which doesn't let you put arbitrary code in the middle of it. Or at the very least, you put that code in GROUP!s.

Perhaps MAKE OBJECT! itself should have that requirement. It could be like PARSE and just ignore the GROUP!s as it goes.

1 Like