On Jun 9, 2015, at 9:23 AM, Kevin Smith 
<[email protected]<mailto:[email protected]>> wrote:

Anyway, I'm curious to know why do you think getters and setters are OK and 
properties are not. I don't see any technical difference, specially considering 
get/set for lazy property computation/assignment through the prototype getter 
anyway.

Syntax for putting properties on the prototype was long-ago rejected because of 
footgun potential.  Users will naturally tend to think of them as per-instance, 
instead of shared, which leads to bugs.

Another way of eliminating the footgun potential is not allowing non-primitive 
defaults on properties. Any non-primitive properties would always default to 
undefined, forcing you to later initialize it yourself in the constructor. 
Defining the property without a default would just be a way to defining what 
the type is supposed to be. As far as I can tell this is what other languages 
do - non-primitive types are not allowed as property defaults. That makes sense 
to me.

```js
class Person {
  name String: “John”
  items Array

  constructor() {
    this.items = [“food"];
  }
}
```

Also static properties are on __proto__, so it seems a bit strange that 
instance properties would not also be on .prototype. Somewhat of a consistency 
issue I suppose.

(My fault for dragging this a bit off topic. TMI in my description of class 
properties…)

Luke
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to