Ideas on type hinting and named parameters

Luke Scott luke at webconnex.com
Tue Jun 9 18:19:12 UTC 2015


On Jun 9, 2015, at 9:23 AM, Kevin Smith <zenparsing at gmail.com<mailto:zenparsing at gmail.com>> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150609/af2239c7/attachment.html>


More information about the es-discuss mailing list