New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why function.name is not well known symbol? #742

Closed
laland opened this Issue Nov 30, 2016 · 5 comments

Comments

Projects
None yet
3 participants
@laland

laland commented Nov 30, 2016

No description provided.

@UltCombo

This comment has been minimized.

Show comment
Hide comment
@UltCombo

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.

Contributor

UltCombo commented Nov 30, 2016

Do you mean Function.prototype.name or (function() {}).name? In any case, it is not a symbol, it is just a property.

@laland

This comment has been minimized.

Show comment
Hide comment
@laland

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 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```?

@michaelficarra

This comment has been minimized.

Show comment
Hide comment
@michaelficarra

michaelficarra Nov 30, 2016

Member

This conversation should be moved to es-discuss. Please see the CONTRIBUTING.md document.

Member

michaelficarra commented Nov 30, 2016

This conversation should be moved to es-discuss. Please see the CONTRIBUTING.md document.

@UltCombo

This comment has been minimized.

Show comment
Hide comment
@UltCombo

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"
Contributor

UltCombo commented Nov 30, 2016

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"
@laland

This comment has been minimized.

Show comment
Hide comment
@laland

laland Nov 30, 2016

Oh, looks like i missed that x_x Thanks for explanation )

laland commented Nov 30, 2016

Oh, looks like i missed that x_x Thanks for explanation )

@laland laland closed this Nov 30, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment