tc39 / proposal-class-fields

Orthogonally-informed combination of public and private fields proposals
https://arai-a.github.io/ecma262-compare/?pr=1668
1.72k stars 113 forks source link

There is a problem with the [Set] and [Define ] #287

Closed 1316346949 closed 4 years ago

1316346949 commented 4 years ago

shi111

1316346949 commented 4 years ago

[Set] “a” will be written to the log because a is already set by class C. From the log we can know that a has been set by class C, so we can find the problem through the log.

1316346949 commented 4 years ago

But [Define] “a” cannot.

1316346949 commented 4 years ago

class A may have many fields, we can't understand how these fields are implemented

1316346949 commented 4 years ago

image

According to the proposal-decorators hint, if we don't know how many fields there are in class A, we can only write this code to ensure that the logging function performs normally.

1316346949 commented 4 years ago

In most cases we don't know how many fields there are in class A. We can only write -> @set xxx = xxx

1316346949 commented 4 years ago

So in most cases, [Define ] will not be used, because we don't know how many fields the parent class has, and what these fields look like. We pretend to use [Define ]. There may be bugs without prompting. just can use "@set xxx = xxx or construtor" to ensure that the program runs normally, or to fully understand all the fields of the parent class, use [Define ]

1316346949 commented 4 years ago

Sorry my english is not good, is there a clear description

nicolo-ribaudo commented 4 years ago

Please try to keep your description in a single comment. It's really hard to read through multiple "answers".

I don't understand how this issue is related to [[Set]] vs [[Define]]. Even with [[Set]], the superclass won't log anything for b = and c =, because you didn't define setters for these properties.