Dart has something like this:
https://www.dartlang.org/guides/language/language-tour#constructors
```dart
class Point {
num x, y;
// Syntactic sugar for setting x and y
// before the constructor body runs.
Point(this.x, this.y);
}
```
I could see a form of BindingElement (et al) that allows `this` or `this` `.`
BindingIdentifier:
```js
class Point {
constructor(this.x, this.y) {}
}
new Point(10, 20).x; // 10
class Foo {
constructor(this.x, { y: this.z, …this }) {}
}
const f = new Foo(1, { y: 2, w: 3 });
f.x; // 1
f.z; // 2
f.w; // 3
```
TypeScript has something similar for constructors in the form of “parameter
property assignments”, but they are triggered by the presence of an modifier
(i.e. `public`, `private`, `protected`, `readonly`).
Ron
From: es-discuss <[email protected]> On Behalf Of Claude Pache
Sent: Wednesday, November 28, 2018 11:46 AM
To: Simo Costa <[email protected]>
Cc: [email protected]
Subject: Re: Proposal for faster this assignments in constructor functions
Le 28 nov. 2018 à 19:32, Simo Costa
<[email protected]<mailto:[email protected]>> a écrit :
In costructor functions and in the constructor() method in ES6 classes is
easily to fall in the following pattern:
F(par1, par2, ..., parN) {
this.par1 = par1;
this.par2 = par2;
...
this.parN = parN;
}
So my proposal is to avoid those repetitions by prefixing a dot . to each
parameter:
F(.par1, .par2, ..., .parN) {}
Simple but quite useful. More info here:
https://github.com/jfet97/proposal-fast-this-assignments<https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fjfet97%2Fproposal-fast-this-assignments&data=02%7C01%7Cron.buckton%40microsoft.com%7C259306c32d9d4c9d053308d6556a246a%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636790311735674930&sdata=8fEkmw%2BDL94JClmv9jv7c13okC7Myd4kxCNNSNjA1LE%3D&reserved=0>
Simple, but a brand new and nonobvious syntax, for a relatively limited use
case.
Also, just one dot is too inconspicuous. At the very least, I’d prefer:
```js
function F(this.par1, this.par2, this.par3) { }
```
whose meaning is somewhat more intuitive.
Also noteworthy: in many cases, you can already reduce repetition with the
combination of `Object.assign`, improved syntax literal, and imagination; see:
http://2ality.com/2014/12/es6-oop.html#use-cases-for-objectassign<https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2F2ality.com%2F2014%2F12%2Fes6-oop.html%23use-cases-for-objectassign&data=02%7C01%7Cron.buckton%40microsoft.com%7C259306c32d9d4c9d053308d6556a246a%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636790311735684942&sdata=1L%2F6iyFqjV7EWd51XhKUWGUnKTrGCW%2FXU6o4RAQESVA%3D&reserved=0>
—Claude
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss