Reputation: 325
I'm reading class fields proposal for JavaScript. I don't understand why the authors call it 'fields' and not properties.
MDN docs in class article speak about instance properties declared inside constructor and in next section about field declarations declared using new syntax.
What is the difference between the two besides the syntax?
Upvotes: 20
Views: 4636
Reputation: 21
Your point is right but my side or opinion about class fields are a new feature in javaScript that introduced ECMAScript 2019.
FACT : This new feature is not yet officially part of the language specification and is not standardized in JavaScript. It is only supported by modern web browsers such as Chrome, Safari, and Firefox. Currently, it is at "stage 3," and it may be released at "stage 4" in the future. It is still under construction and will likely become official in the near future.
Highlight : Class field as "data properties" and "behavior/method" that declarer and initialize instance variable and contain also instances of class. They published two types such as public and private.
Upvotes: 2
Reputation: 1075109
What is the difference between the two besides the syntax?
There isn't any. A public field is an instance property, just one created with a field definition rather than by assignment. Other than how they're created, they're exactly the same thing.
The term "field" was used so it could cover both public and private (since private fields are not properties).
Upvotes: 19