Your imagined syntax would suggest to me that the constructor had 5
arguments, not 3 - it seems strange to me to have "x" and "a" be implicitly
two ways to refer to the same thing.

On Thu, Dec 6, 2018 at 8:56 AM dante federici <[email protected]>
wrote:

> 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;
>   }
> }
> ```
>
> _______________________________________________
> es-discuss mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/es-discuss
>
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to