Re: New: proposal-common-member-modifiers
I'm of the opinion this is what decorators are for. On Sun, Dec 2, 2018, 01:49 Ranando King Since some form of data is going to land in ES class syntax, it would be a > good idea if the capabilities of a property descriptor were also exposed > for all public properties. > > https://github.com/rdking/proposal-common-member-modifiers > ___ > 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
New: proposal-common-member-modifiers
Since some form of data is going to land in ES class syntax, it would be a good idea if the capabilities of a property descriptor were also exposed for all public properties. https://github.com/rdking/proposal-common-member-modifiers ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Proposal for faster this assignments in constructor functions
``this = { ...this, par1, par2, par3 }``` Oh, wait, I'm going to point out the problem with what I wrote before anyone else does: this will lose any non-enumerable properties on `this`, which in a class instance is kind of a big no-no. `Object.assign` is better here. On Sat, 1 Dec 2018 at 20:08 Michael Luder-Rosefield wrote: > > ```js > this.{} = {par1, par2, par3}; > ``` > > Of course, that could be expressed as ```this = { ...this, par1, par2, > par3 }```, but that's still a bit verbose. > > I already know this is going to get dismissed for changing the way the `+` > operator works, but it strikes me that a better way of expressing that > might be ```this += { par1, par2, par3 }```. > > That naturally leads to having ```obj1 + obj2 === Object.assign(obj1, > obj2)``` and ```arr1 + arr2 === (arr1 = [ ...arr1, ...arr2 ])```, which > would be good except for the whole breaking-change thing. > > On Fri, 30 Nov 2018 at 22:52 Simo Costa wrote: > >> Thank you T.J. Crowder for giving me your opinion on this proposal. >> I didn't know about the Bob Myers' for pick notation and it isn't bad. >> >> I still prefer something like that: >> ```js >> constructor(this.{par1, par2, par3}) { >> } >> ``` >> >> but this doesn't sound bad to me: >> >> ```js >> constructor(par1, par2, par3) { >> this.{} = {par1, par2, par3}; >> } >> ``` >> >> There is still a repetition, but it is a a step forward. >> >> Il giorno gio 29 nov 2018 alle ore 12:28 T.J. Crowder < >> tj.crow...@farsightsoftware.com> ha scritto: >> >>> On Wed, Nov 28, 2018 at 6:33 PM Simo Costa >>> wrote: >>> > >>> > So my proposal is to avoid those repetitions... >>> >>> I'm a bit surprised to find that no one's mentioned Bob Myers' >>> [proposal][1] for pick notation yet, which would readily address this >>> requirement *and* various other requirements beyond initializing >>> newly-constructed objects. >>> >>> Using Bob's current draft syntax, Simo's example would be: >>> >>> ```js >>> constructor(par1, par2, par3) { >>> this.{par1, par2, par3} = {par1, par2, par3}; >>> } >>> ``` >>> >>> or if the constructor accepts an object: >>> >>> ```js >>> constructor(options) { >>> this.{par1, par2, par3} = options; >>> } >>> ``` >>> >>> But I think we can go further if we tweak the syntax a bit. Perhaps: >>> >>> ```js >>> constructor(par1, par2, par3) { >>> this.{} = {par1, par2, par3}; >>> } >>> ``` >>> >>> ...where the property names are inferred from the properties on the >>> right-hand side. That would be functionally equivalent to: >>> >>> ```js >>> constructor(par1, par2, par3) { >>> Object.assign(this, {par1, par2, par3}); >>> } >>> ``` >>> >>> ...but since the syntax is clear about the intent, when an object >>> initializer (rather than just object reference) is used on the right-hand >>> side it's an optimization target if a constructor is "hot" enough to >>> justify it (e.g., an engine could optimize it into individual assignments). >>> >>> For me, that would be a great, clear, concise feature, and hits the >>> other use cases Bob mentions in his proposal. I like that I'm still in >>> control of what parameters get assigned as properties (which I think has >>> been true of all of the suggestsions in this thread). >>> >>> -- T.J. Crowder >>> >>> [1]: https://github.com/rtm/js-pick-notation >>> >> ___ >> 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: Proposal for faster this assignments in constructor functions
@Michael Luder-Rosefield ```js this += { par1, par2, par3 } ``` I do love it!!! Il giorno sab 1 dic 2018 alle ore 12:08 Michael Luder-Rosefield < rosyatran...@gmail.com> ha scritto: > > ```js > this.{} = {par1, par2, par3}; > ``` > > Of course, that could be expressed as ```this = { ...this, par1, par2, > par3 }```, but that's still a bit verbose. > > I already know this is going to get dismissed for changing the way the `+` > operator works, but it strikes me that a better way of expressing that > might be ```this += { par1, par2, par3 }```. > > That naturally leads to having ```obj1 + obj2 === Object.assign(obj1, > obj2)``` and ```arr1 + arr2 === (arr1 = [ ...arr1, ...arr2 ])```, which > would be good except for the whole breaking-change thing. > > On Fri, 30 Nov 2018 at 22:52 Simo Costa wrote: > >> Thank you T.J. Crowder for giving me your opinion on this proposal. >> I didn't know about the Bob Myers' for pick notation and it isn't bad. >> >> I still prefer something like that: >> ```js >> constructor(this.{par1, par2, par3}) { >> } >> ``` >> >> but this doesn't sound bad to me: >> >> ```js >> constructor(par1, par2, par3) { >> this.{} = {par1, par2, par3}; >> } >> ``` >> >> There is still a repetition, but it is a a step forward. >> >> Il giorno gio 29 nov 2018 alle ore 12:28 T.J. Crowder < >> tj.crow...@farsightsoftware.com> ha scritto: >> >>> On Wed, Nov 28, 2018 at 6:33 PM Simo Costa >>> wrote: >>> > >>> > So my proposal is to avoid those repetitions... >>> >>> I'm a bit surprised to find that no one's mentioned Bob Myers' >>> [proposal][1] for pick notation yet, which would readily address this >>> requirement *and* various other requirements beyond initializing >>> newly-constructed objects. >>> >>> Using Bob's current draft syntax, Simo's example would be: >>> >>> ```js >>> constructor(par1, par2, par3) { >>> this.{par1, par2, par3} = {par1, par2, par3}; >>> } >>> ``` >>> >>> or if the constructor accepts an object: >>> >>> ```js >>> constructor(options) { >>> this.{par1, par2, par3} = options; >>> } >>> ``` >>> >>> But I think we can go further if we tweak the syntax a bit. Perhaps: >>> >>> ```js >>> constructor(par1, par2, par3) { >>> this.{} = {par1, par2, par3}; >>> } >>> ``` >>> >>> ...where the property names are inferred from the properties on the >>> right-hand side. That would be functionally equivalent to: >>> >>> ```js >>> constructor(par1, par2, par3) { >>> Object.assign(this, {par1, par2, par3}); >>> } >>> ``` >>> >>> ...but since the syntax is clear about the intent, when an object >>> initializer (rather than just object reference) is used on the right-hand >>> side it's an optimization target if a constructor is "hot" enough to >>> justify it (e.g., an engine could optimize it into individual assignments). >>> >>> For me, that would be a great, clear, concise feature, and hits the >>> other use cases Bob mentions in his proposal. I like that I'm still in >>> control of what parameters get assigned as properties (which I think has >>> been true of all of the suggestsions in this thread). >>> >>> -- T.J. Crowder >>> >>> [1]: https://github.com/rtm/js-pick-notation >>> >> ___ >> 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: Proposal for faster this assignments in constructor functions
@T.J. Crowder No problems for the error :P. Anyway I know Typescript's approach but I prefer something like: ```js class Example { constructor(this.{foo, #bar}) { } showFoo() { console.log(e1.foo); } showBar() { console.log(e1.#bar); } } const e1 = new Example("answer", 42); e1.showFoo(); // "answer" e1.showBar(); // 42 ``` To both declare, if not already declared, and initialize public and private properties. Il giorno sab 1 dic 2018 alle ore 11:13 T.J. Crowder < tj.crow...@farsightsoftware.com> ha scritto: > On Fri, Nov 30, 2018 at 5:49 PM T.J. Crowder > wrote: > > > which is > > > > ```js > > class Example { > > ... > > } > > Apologies, that "which is" at the end of my previous message should have > been: > > ```js > class Example { > second; > #third; > fifth; > constructor(first, second, third, fourth, fifth) { > this.second = second; > this.#third = third; > this.fifth = fifth; > // presumably code here uses `first` and `fourth` > } > } > ``` > > Editing error. :-) > > -- T.J. Crowder > ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Proposal for faster this assignments in constructor functions
> ```js this.{} = {par1, par2, par3}; ``` Of course, that could be expressed as ```this = { ...this, par1, par2, par3 }```, but that's still a bit verbose. I already know this is going to get dismissed for changing the way the `+` operator works, but it strikes me that a better way of expressing that might be ```this += { par1, par2, par3 }```. That naturally leads to having ```obj1 + obj2 === Object.assign(obj1, obj2)``` and ```arr1 + arr2 === (arr1 = [ ...arr1, ...arr2 ])```, which would be good except for the whole breaking-change thing. On Fri, 30 Nov 2018 at 22:52 Simo Costa wrote: > Thank you T.J. Crowder for giving me your opinion on this proposal. > I didn't know about the Bob Myers' for pick notation and it isn't bad. > > I still prefer something like that: > ```js > constructor(this.{par1, par2, par3}) { > } > ``` > > but this doesn't sound bad to me: > > ```js > constructor(par1, par2, par3) { > this.{} = {par1, par2, par3}; > } > ``` > > There is still a repetition, but it is a a step forward. > > Il giorno gio 29 nov 2018 alle ore 12:28 T.J. Crowder < > tj.crow...@farsightsoftware.com> ha scritto: > >> On Wed, Nov 28, 2018 at 6:33 PM Simo Costa >> wrote: >> > >> > So my proposal is to avoid those repetitions... >> >> I'm a bit surprised to find that no one's mentioned Bob Myers' >> [proposal][1] for pick notation yet, which would readily address this >> requirement *and* various other requirements beyond initializing >> newly-constructed objects. >> >> Using Bob's current draft syntax, Simo's example would be: >> >> ```js >> constructor(par1, par2, par3) { >> this.{par1, par2, par3} = {par1, par2, par3}; >> } >> ``` >> >> or if the constructor accepts an object: >> >> ```js >> constructor(options) { >> this.{par1, par2, par3} = options; >> } >> ``` >> >> But I think we can go further if we tweak the syntax a bit. Perhaps: >> >> ```js >> constructor(par1, par2, par3) { >> this.{} = {par1, par2, par3}; >> } >> ``` >> >> ...where the property names are inferred from the properties on the >> right-hand side. That would be functionally equivalent to: >> >> ```js >> constructor(par1, par2, par3) { >> Object.assign(this, {par1, par2, par3}); >> } >> ``` >> >> ...but since the syntax is clear about the intent, when an object >> initializer (rather than just object reference) is used on the right-hand >> side it's an optimization target if a constructor is "hot" enough to >> justify it (e.g., an engine could optimize it into individual assignments). >> >> For me, that would be a great, clear, concise feature, and hits the other >> use cases Bob mentions in his proposal. I like that I'm still in control of >> what parameters get assigned as properties (which I think has been true of >> all of the suggestsions in this thread). >> >> -- T.J. Crowder >> >> [1]: https://github.com/rtm/js-pick-notation >> > ___ > 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: Proposal for faster this assignments in constructor functions
On Fri, Nov 30, 2018 at 5:49 PM T.J. Crowder wrote: > which is > > ```js > class Example { > ... > } Apologies, that "which is" at the end of my previous message should have been: ```js class Example { second; #third; fifth; constructor(first, second, third, fourth, fifth) { this.second = second; this.#third = third; this.fifth = fifth; // presumably code here uses `first` and `fourth` } } ``` Editing error. :-) -- T.J. Crowder ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss