5

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?

Bergi
  • 513,640
  • 108
  • 821
  • 1,164
bifi
  • 73
  • 4
  • Field declarations are a new and experimental piece of syntax sugar for the new ES6 classes. – Jack Bashford Feb 24 '19 at 11:05
  • 1
    @JackBashford - Not so much "experimental" at this point. They're [Stage 3](https://tc39.github.io/process-document/) and actively being added to JavaScript engines. Public fields are already in V8, shipping in Chrome without any flags. – T.J. Crowder Feb 24 '19 at 11:07
  • Sorry @T.J.Crowder I was based off the MDN page provided – Jack Bashford Feb 24 '19 at 11:10

1 Answers1

2

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).

T.J. Crowder
  • 879,024
  • 165
  • 1,615
  • 1,639