proposal-symbol-thenable icon indicating copy to clipboard operation
proposal-symbol-thenable copied to clipboard

No need for Symbol to be visible on Module Namespace

Open bmeck opened this issue 7 years ago • 6 comments

A variety of Symbols can be used to change behaviors but are not always exposed / used for exotic objects:

class X {};
Object.setPrototypeOf(X, null);

// undefined, true
console.log(X[Symbol.hasInstance], new X() instanceof X);

bmeck avatar May 22 '18 14:05 bmeck

The entire reason for this proposal is because the committee did not want magic behavior for Namespace objects; they wanted a general-purpose solution.

ljharb avatar May 22 '18 14:05 ljharb

The entire reason for this proposal is because the committee did not want magic behavior for Namespace objects; they wanted a general-purpose solution.

I don't think these are mutually exclusive. Taking Bradley's example where functions have some unexposed behavior there's also user-facing parts like Symbol.hasInstance and even a proxy trap. So while parts can be unexposed other parts can be exposed.

jdalton avatar May 22 '18 15:05 jdalton

what people seemed to want was a consistent way to be able to explain why object X isn't behaving like object Y. the most obvious way to go about that with the current mechanics we have available seemed to me to be a symbol.

devsnek avatar May 22 '18 15:05 devsnek

I don't see it specified in this proposal but is the idea that for namespace objects it would be non-enumerable, non-configurable, non-writable like the namespace @@toStringTag?

jdalton avatar May 22 '18 15:05 jdalton

@jdalton yeah; its not in the readme but i put it in spec.html: https://gus.host/proposal-symbol-thenable/#sec-@@thenable

devsnek avatar May 22 '18 15:05 devsnek

That's more of a stage 2 concern, but yes, I would imagine so - module namespace objects are meant to be fully immutable.

(edit: sorry, closed by accident)

ljharb avatar May 22 '18 15:05 ljharb