Property names for public symbols
Agreed, like at the constants on the Math object.
An HTML attachment was scrubbed... URL: esdiscuss/attachments/20150207/e25e3f5c/attachment
Some tasteful inconsistency (the hobgoblin of big minds) is required here. We want the well known symbols' names as static properties of Symbol to be same-named.
Can you explain what you mean by “same-named”? You want Symbol.for()
to have the same casing as Symbol.iterator
?
No, I mean we would normally use iterator (and had __iterator__
in
SpiderMonkey, then '@@iterator'
I believe), not ITERATOR
. Python's
dunder-bracketing doesn't cut it, symbols win. But UPPERCASE loses.
Got it: public symbols stand for property names and those are typically camel-case, starting with a lowercase letter.
I'm curious why one of the public symbols has a name that ends with "Tag" ("toStringTag"), but the others don't (such as "toPrimitive"). Maybe "toStringTag" should be changed to "toString".
This symbol is about the string tag.
Mark Volkmann wrote:
I'm curious why one of the public symbols has a name that ends with "Tag" ("toStringTag"), but the others don't (such as "toPrimitive"). Maybe "toStringTag" should be changed to "toString".
That would be the wrong name -- the Tag is specific, particular to the purpose of this symbol. It's not an under-used generic suffix for all well-known symbol names. See people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring.
How about "classTag" instead of "toStringTag", which makes it sound like a noun.
"[[Class]]" was the pre-ES6 term to refer to this value, but with the ES6 "class" keyword that would be confusing, and I don't think it would be a good idea to conflate the meaning of the term even further. "toString" is a common single idiom in JS since it's the function that String() invokes, so "toStringTag" works for me.
This particular value is one that, imo, in practice should be rarely used (once per "class" perhaps, in its definition), so I'm not hugely concerned about the naming (my concerns were about the behavior). My guess would be that in order to effect a change at this very late date, one would have to propose a name that was so compelling as to make it an obvious choice.
Actually I disagree with you. Class
will not be confusing, since as you said, people probably will use toStringTag
once per class
. So classTag
just becomes a better name. String, Boolean, etc, are just names of classes.
Based on my understanding of the spec, I'd say that String, Boolean, etc are not "classes" at all, since they don't have a [[HomeObject]] - they're just constructor functions.
I know that this is a small nit and that it’s probably too late, but: Shouldn’t public symbols (
Symbol.iterator
etc.) have all-uppercase property names? It would indicate that they are constants and it would visually set them apart from other stuff that is inSymbol
(Symbol.for()
etc.).