Dash-case keys

# Sultan (6 months ago)

Is there any reason that dash-case keys are not supported in the object literal syntax.

For example:

const style = { font-size: 10 }

Compared to what one needs to do today:

const style = { 'font-size': 10 }

# Jordan Harband (6 months ago)

is that a key called "font-size" or the subtraction of size from font?

# Sultan Tarimo (6 months ago)

The former as the following is equally invalid syntax errors:

const font = 1 const size = 1

const a = { font-size: 10 } const b = { font+size: 10 }

# Jordan Harband (6 months ago)

i think if i can use something unquoted in an object literal, i'd expect to be able to use it in dot access - ie, obj.font-size - and then that problem arises.

# Sultan Tarimo (6 months ago)

That might have been the case, but the expectation that an unquoted form should equally have a quoted form or vice-versa is not an issue in practice given the presence of a similar but opposite semantic in the private sigil access notation proposal: object.#validPrivateSigil -> object[‘#invalidPrivateSigil’].

In kind, this would exploit the same grammar affordances to be born from this.

That is obj.font-size would rightly be invalid. The more common interfacing with this notation would be through iterators. That is:

for (var key in object) { style.setProperty(key, object[key]) }

The addition of which would see to improve the ergonomics with using dash-case keys common in the CSS grammar within the object literals syntax.

# Claude Pache (6 months ago)

Le 29 janv. 2019 à 08:45, Sultan Tarimo <thysultan at gmail.com> a écrit :

That is obj.font-size would rightly be invalid.

Sadly, obj.font-size is not invalid, it has some well-defined semantics. That would be a source of bugs

# Sultan Tarimo (6 months ago)

This is expected and by design. For example obj[‘#invalidPrivateSigil’] is also not invalid. The affordances would be the same.

# Jordan Harband (6 months ago)

There's a difference, though, between private field access - an entirely distinct and new kind of thing - and normal property access, a well-established and understood thing.

# T.J. Crowder (6 months ago)

On Tue, Jan 29, 2019 at 7:45 AM Sultan Tarimo <thysultan at gmail.com> wrote:

That is obj.font-size would rightly be invalid.

By which I think you mean, would still be obj.font - size with its current meaning.

I don't think the confusion that causes is worth the benefit of not putting the name in quotes in the object initializer. Particularly not with the well-established convention of using camelCase in that situation when interoperating with objects that have (or act like they have) dash-named properties (like the CSSStyleDeclaration object on HTML elements).

-- T.J. Crowder