Deep creation of object...

var x.chrome.tab = true
Binding variable like this could actually set it up as nested object, instead of giving error that it cannot access it from certain point.

1 Like

What's the point? Just write what you mean to do:

var x = {chrome: {tab: true}};

I don't see the problem that this is trying to solve.

3 Likes

Because then in nested structures you have to overwrite whole objects, or use Object.Assign... Both of which are unnecessary crap standing in million lines of finished code every day.

A quick solution is using camel-case. i.e.
var xChromeTab = true;

To achieve this idea, I think that we need a feature that group/nest some properties, instead of using an object.

Take element.style.borderBottomColor in DOM/CSSOM as an example:

A feature that allows writing element.style.border.bottom.color without nesting objects
and it represents as a flatten internal property, say "styleBorderBottomColor" of element object.

I agree that writing or trying to read a nested Object.assign is no fun.

// var x.chrome.tab = true
Object.assign(
  x, { chrome: Object.assign(x.chrome ?? {},
    { tab: true }
  )}
)

One alternative is to use lodash - set

import set from 'lodash/set';

set(x, 'chrome.tab', true);
// or
set(x, ['chrome', 'tab'], true);