Le 11 févr. 2014 à 20:04, Allen Wirfs-Brock <[email protected]> a écrit :
>
> Symbol("string") is a symbol factory call, not a coercion of "string" to a
> symbol. The argument is not a value to be coerced to symbol but a string
> value that is part of the state of the new symbol value. In particular:
> console.log(Symbol("x") === Symbol("x")) //false, each call to Symbol
> returns a new unique symbol value
>
> If Symbol(sym) returned sym, that would break the invariant that calling
> Symbol always produces a new symbol value. Rather that reenforcing the fact
> the Symbol has its own usage patterns that are different from
> Number/String/Boolean it would partially blur that distinction.
>
Good point. `Symbol(x)` consistently produces a different value at each call,
whereas for other primitives, `Primitive(x)` consistently produces the same
value.
If we wanted absolutely to be consistent with other primitives, we could make
`Symbol(...)` a function that casts to symbol (and, in fact, throws a TypeError
in most cases), and use another function (e.g., `Symbol.spawn("name")`) in
order to produce new symbols. But it is probably not worth to do that.
—Claude
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss