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.
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to