Closed smikes closed 9 years ago
Consider the following code:
const s = Symbol("Foo.bar");
const o = { get [s]() { return "b"; } };
console.log(Object.getOwnPropertyDescriptor(o, s).get.name); // outputs "get [Foo.bar]"
Am I missing a way to set the function name?
Well, it is configurable in ES6, although not in ES5 so that probably doesn't help transpilers.
so that probably doesn't help transpilers.
Indeed. Since the line specifying the name doesn't seem to do anything but document behavior that springs from other parts of the spec, can it be dropped?
No, it cannot be dropped. From ch. 17:
Every built-in Function object, including constructors, that is not identified as an anonymous function has a name property whose value is a String. Unless otherwise specified, this value is the name that is given to the function in this specification. For functions that are specified as properties of objects, the name value is the property name string used to access the function. Functions that are specified as get or set accessor functions of built-in properties have "get " or "set " prepended to the property name string. The value of the name property is explicitly specified for each built-in functions whose property key is a symbol value.
Can you file a bug at bugs.ecmascript.org for the missing whitespace in "get[Symbol.species]"
?
ES5 does not have a function name property. Some engines did but not all of them. ES6 adds it and makes it configurable so that we do not need to standardize (and implement) displayName.
Can you file a bug at bugs.ecmascript.org for the missing whitespace in "get[Symbol.species]" ?
Will do.
Will do.
Thanks!
Related topic: Should WeakMap and WeakSet also have Symbol.species ?
Why would they?
Dumb parallelism? Because otherwise "Why does Set have Symbol.species but WeakSet does not" will wind up on a FAQ somewhere... or maybe just an IAQ.
Symbol.species is only useful for classes that create instances of themselves.
var m = WeakSet()
///
Array.prototype.map.call(m, function () {...})
will return an Array, then? Or.. hang on, throws an error, because there is no defined way to iterate over a WeakSet ? (No need to answer, clearly I have reading to do. :-)
Per https://people.mozilla.org/~jorendorff/es6-draft.html#sec-get-regexp-@@species
Also per https://people.mozilla.org/~jorendorff/es6-draft.html#sec-get-array-@@species
First issue: inconsistency between names here. I think that's just a typo.
This seems unnecessarily strict. Also, since the
name
property of a function is immutably constructed when the function is created, it puts a needless barrier in the way of of transpilers and non-native implementations of ES6.Am I missing a way to set the function name? Thoughts? Is this a spec bug? /cc @bterlson @anba @rwaldron