andrysimo1997 at gmail.com (2018-11-29T08:46:21.252Z)
When or more than one parameters should be inserted into an object we could
do like that:
`f(.{par1, par2, parN}) {}`
equivalent to:
`f(this.{par1, par2, parN}) {}`
that is equivaent to:
`f(.par1, .par2, .parN) {}`
and:
`f(this.par1, this.par2, this.parN) {}`
SO we could write that:
`f(obj.par1, obj.par2, obj2.parN) {}`
in this way:
`f(obj.{par1, par2}, obj2.parN) {}`
going faster When or more than one parameters should be inserted into an object we could do like that: f(.{par1, par2, parN}) {} equivalent to: f(this.{par1, par2, parN}) {} that is equivaent to: f(.par1, .par2, .parN) {} and: f(this.par1, this.par2, this.parN) {} SO we could write that: f(obj.par1, obj.par2, obj2.parN) {} in this way: f(obj.{par1, par2}, obj2.parN) {} Il giorno gio 29 nov 2018 alle ore 09:42 Simo Costa <andrysimo1997 at gmail.com> ha scritto: > going faster > > When or more than one parameters should be inserted into an object we > could do like that: > > f(.{par1, par2, parN}) {} > > equivalent to: > > f(this.{par1, par2, parN}) {} > > that is equivaent to: > > f(.par1, .par2, .parN) {} > > and: > > f(this.par1, this.par2, this.parN) {} > > > SO we could write that: > > f(obj.par1, obj.par2, obj2.parN) {} > > in this way: > > f(obj.{par1, par2}, obj2.parN) {} > > > Il giorno gio 29 nov 2018 alle ore 09:00 Simo Costa < > andrysimo1997 at gmail.com> ha scritto: > >> Thanks for partecipating to this discussion and for your opinions on my >> proposal. I cannot reply to each one of you now, but I'd like to receive >> feedback also on the Further Ideas section. Maybeyou'll find something >> interesting. >> >> In JS there is no way (please correct me if you find the way) to gather >> all arguments directly in a object (without passing directly an object obv) >> like you can easily do with an array. >> >> So, to mantain this way to pass the arguments: >> >> ``` >> >> f(arg1, arg2, arg3); >> >> ``` >> >> you could do like that to store them into an array: >> >> ``` >> >> function f(...args){ >> >> /* code */ >> >> } >> >> ``` >> >> but something like that won't work if u want gather them into a obj: >> >> `` >> >> function f({...obj}){ >> >> /* code */ >> >> } >> >> ``` >> >> My proposal could solve this problem. >> >> >> P.S. >> >> Though you pass an object created on the fly (and this is wath I'd like >> to avoid): >> >> ``` >> >> f( { arg1, arg2, arg3 } ); >> >> ``` >> to make that work: >> >> `` >> >> function f({...obj}){ >> >> /* code */ >> >> } >> >> ``` >> you cannot do something like that directly: >> >> ``` >> >> function a ( { arg1: obj.arg1, arg2: obj2.arg2, arg3: obj2.arg3 }) {} >> >> ``` >> My proposal theoretically could solve this "problem" too. >> >> Il giorno gio 29 nov 2018 alle ore 00:59 Ron Buckton < >> Ron.Buckton at microsoft.com> ha scritto: >> >>> 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 <es-discuss-bounces at mozilla.org> * On Behalf Of *Claude >>> Pache >>> *Sent:* Wednesday, November 28, 2018 11:46 AM >>> *To:* Simo Costa <andrysimo1997 at gmail.com> >>> *Cc:* es-discuss at mozilla.org >>> *Subject:* Re: Proposal for faster this assignments in constructor >>> functions >>> >>> >>> >>> >>> >>> Le 28 nov. 2018 à 19:32, Simo Costa <andrysimo1997 at gmail.com> 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 >>> >>> >>> >> -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20181129/146b5154/attachment-0001.html>