Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upWhy function.name is not well known symbol? #742
Comments
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
UltCombo
Nov 30, 2016
Contributor
Do you mean Function.prototype.name or (function() {}).name? In any case, it is not a symbol, it is just a property.
|
Do you mean |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
laland
Nov 30, 2016
I mean Function.prototype.name, i know that it's not a symbol. But "name" is a such common concept for classes (that are functions in ES). Lots of classes have a "name" property to represent the names of the things, like class Hotel will have a name property to store hotel name, class Brand will have name to represent brand name, and so on... By defining name property in my class i`ll lose ability to get class name with Function.prototype.name. ES has the concept of "well known symbols", like ```@@iterator``` or ```@@toPrimitive```, which purpose was to have some internal properties that can't be accidentally overriden by user. But we still have the ```Function.prototype.name```. Why it's not a ```@@name``` or ```name```?
laland
commented
Nov 30, 2016
|
I mean |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
michaelficarra
Nov 30, 2016
Member
This conversation should be moved to es-discuss. Please see the CONTRIBUTING.md document.
|
This conversation should be moved to es-discuss. Please see the |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
UltCombo
Nov 30, 2016
Contributor
Oh, I see. If it is a feature request for a new symbol, then it should be moved to ES Discuss as Michael commented.
ECMAScript must have strong backwards compatibility in order to not break the web, and the name property has been there since forever. Classes also have been designed to be mostly compatible with the existing constructor patterns and avoid refactoring hazards.
So the name property cannot be removed and there's no strong motivation to add a symbol for that so far.
By defining name property in my class i`ll lose ability to get class name with Function.prototype.name.
What exactly do you mean? Assigning a name to the instance will not affect the class/constructor name:
class C {
constructor() {
this.name = "instance name";
}
}
console.log(C.name); // "C"
const c = new C();
console.log(c.name); // "instance name"
console.log(c.constructor.name); // "C"|
Oh, I see. If it is a feature request for a new symbol, then it should be moved to ES Discuss as Michael commented. ECMAScript must have strong backwards compatibility in order to not break the web, and the So the
What exactly do you mean? Assigning a class C {
constructor() {
this.name = "instance name";
}
}
console.log(C.name); // "C"
const c = new C();
console.log(c.name); // "instance name"
console.log(c.constructor.name); // "C" |
laland
referenced this issue
Nov 30, 2016
Closed
Why not to replace Function.prototype.name with Function.prototype[Symbol.name]? #173
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
laland
commented
Nov 30, 2016
|
Oh, looks like i missed that x_x Thanks for explanation ) |
laland commentedNov 30, 2016
No description provided.