Skip to content
This repository has been archived by the owner on Jan 25, 2022. It is now read-only.

A "field" specifier for instance members? #130

Closed
JorisBlanken opened this issue Sep 12, 2018 · 1 comment
Closed

A "field" specifier for instance members? #130

JorisBlanken opened this issue Sep 12, 2018 · 1 comment

Comments

@JorisBlanken
Copy link

JorisBlanken commented Sep 12, 2018

I can't help but feel that the currently proposed syntax look out of the ordinary.
Consider the following:

class Example {
    x = 5;

    constructor(){
    }
}

Eventhough x = 5; is part of the class definition, it appears to belong to a piece of sequential(?) code.

Another issue with simply having x = 5; (without having a clear previous let x; or such) is that it appears too reminiscent of assignment to window/global, something that is considered bad behavior and is resented by many.

Would it be possible to require a new keyword such as field to be added infront of instance members?
Consider the following (imagine field to be treated by syntax highlighting as it would static):

class Example {
    field x = 5;

    constructor(){
    }
}

I believe this would help make instance members appear more definition-like.

I also think this will help normalize the appearance of the # sigil use without having to add public/private specifiers.

@bakkot
Copy link
Contributor

bakkot commented Sep 12, 2018

We discussed having different syntax for declarations (see e.g. here and here) and ultimately decided against it.

For me a fairly compelling argument was that many, many people are using this syntax through TypeScript and Babel without apparent confusion, so there doesn't seem to be an extremely strong need to be more explicit and verbose.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants