Proposal for faster this assignments in constructor functions
dante federici
c.dante.federici at gmail.com
Thu Dec 6 16:56:12 UTC 2018
Any reason we can't consider a scala-like constructor?
```js
class Point(x, y) {
toString() {
return `(${this.x},${this.y})`
}
}
console.log(`??? ${new Point(1, 2)}`); // ??? 1,2
````
Doesn't conflict with existing syntax, it's clear, and you can still
shorthand most data-classes or structs to just:
```
class MyData(some, props, here) {}
```
I imagine this as the syntax:
```
class Point(x, y) { // implicits x, y as first two args of constru
constructor(a, b, c) {
this.z = a + b + c;
console.log(this.x, this.y, this.c); // values of: a, b, c
console.log(this.x === a, this.y === b); // true, true
}
}
```
And de-sugared:
```
class Point {
constructor(a, b, c) {
this.x = a;
this.y = b;
// rest of body
this.z = a + b + c;
}
}
```
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20181206/ea989bf5/attachment.html>
More information about the es-discuss
mailing list