Re: Re: Proposal for faster this assignments in constructor functions

2018-12-06 Thread Jordan Harband
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 
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
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Re: Proposal for faster this assignments in constructor functions

2018-12-06 Thread dante federici
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
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss