Name-spaced cross-realm objects

Sultan thysultan at
Tue Mar 12 04:38:56 UTC 2019

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

// 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

Disclaimer: I'm aware all of the above can be implemented with global state
if you disregard the cross-realm requirement.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list