Comments (9)
I don't see why a field named constructor
(whether it's static or instance) would need any special treatment. We talked about special treatment for fields named __proto__
in the past, but really, there's no particular interaction in either case. If there's a public instance field named constructor
, then a constructor
property is simply added to the instance with [[DefineOwnProperty]] at the appropriate time in the [[Construct]] sequence. You can still get at the "real" constructor through instance.__proto__.constructor
. Do you think we should ban this, though, to avoid confusion?
There's definitely a bug about PropName being misapplied, which I see in one place: when prohibiting static fields named prototype
. I'll fix that up; thanks for the catch.
from proposal-class-fields.
What do you think of this fix?
from proposal-class-fields.
It's not fixed. The PropName call and disallowance of "constructor" I was referring to are coming from NonConstructorMethodDefinitions, which is called by ClassDefinitionEvaluation.
from proposal-class-fields.
- https://tc39.github.io/ecma262/#sec-static-semantics-nonconstructormethoddefinitions
- https://tc39.github.io/ecma262/#sec-runtime-semantics-classdefinitionevaluation
from proposal-class-fields.
Huh?
https://tc39.github.io/proposal-class-fields/#runtime-semantics-class-definition-evaluation
calls NonConstructorMethodDefinitions, which calls PropName on something on which it's not defined. And it will silently drop any fields named constructor
.
from proposal-class-fields.
I was providing links to the sections you mentioned in your comment, for others that might read this thread.
from proposal-class-fields.
@waldemarhorwat Thanks, I wasn't thinking about that path (but I believe the other one was a bug as well); will fix.
from proposal-class-fields.
NonConstructorElementDefinitions currently starts with:
If ClassElement is any of ClassElement:; , FieldDefinition:; or , return a new empty List.
I don't know what that is referring to; that doesn't parse and there are no such grammar productions.
from proposal-class-fields.
@waldemarhorwat Thanks for pointing this out; I should've checked the generated output more closely (the colon doesn't appear in the source but was inserted by grammardown). Uploading a fix in a minute.
from proposal-class-fields.
Related Issues (20)
- Class fields are a time waster. HOT 7
- Motivation for PrivateFieldAdd type error? HOT 5
- Interaction with Integrity Levels? HOT 4
- private field and protected field HOT 1
- Clarify what the context (`this`) for fields declared as anonymous functions will be in the spec. HOT 2
- Inferred function names for number/bigint fields aren't handled right HOT 2
- [Suggestion] Consider to use time proof solution with private and protected keywords HOT 39
- Private fields breaks POI HOT 35
- Support for privates in object literals? HOT 3
- Class composition HOT 3
- [[Define]] semantics causes libraries to lose performance. HOT 2
- class fields with [[Define]] semantics are much slower than with [[Set]] semantics. HOT 3
- [[Define]] semantics necessitate workarounds HOT 7
- Properties without initializers can create some headache in "real-world" scenarios. HOT 14
- Why are #private fields not source-positional? HOT 22
- Statement of our opinions on class fields and its related package of proposals HOT 2
- Proxy nested inside of the Prototype Chain HOT 2
- Please Don't Do That. HOT 8
- Why are class fields so slow? HOT 2
- Constructor arguments with object destructuring HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from proposal-class-fields.