Name-spaced cross-realm objects

# Sultan (6 years ago)

The following is currently possible with setTimeout from the browser

const i = setTimeout(() => {})

Where "i" is a number from 0 incrementing towards infinity.

This however has the issue that it is entirely global, and as the title of the post suggests the idea is to strike a middle ground between global and name-spaced; That is the ability to create/access your own name-spaced state similar to Symbol.for. As an example – a name-spaced incrementing number:

// a.js const fn = UID.for('namespace')

assert(fn() === 0) assert(fn() === 1)

// b.js

const fn = UID.for('namespace')

assert(fn() === 2) assert(fn() === 3)

This however would be implemented in user-land on top of a more general proposal for creating cross realm name-spaced objects:

// a.js const obj = Object.for('namespace')

// b.js const obj = Object.for('namespace')

Where both objects "obj" in the files a.js and b.js would point to the same object.

Disclaimer: I'm aware all of the above can be implemented with global state if you disregard the cross-realm requirement.

# Isiah Meadows (6 years ago)

Not a huge fan. This explicit encapsulation break could be done via an explicit bootstrapper that can send values across realms, and scenarios on the same realm can just use global state. Also, the utility seems a bit low IMHO.