just nobody (2017-03-18T19:32:47.000Z)
kingdaro at gmail.com (2017-03-18T19:37:41.959Z)
> I don't see any point to having this on methods. On constructors, I > suppose it's a bit of convenience. If it's supported on constructor functions, my reasoning was that it'd only make sense for it to be supported on methods (which are also just functions). Having this syntax available for functions allows really nice, convenient data structures, and getter/setters as I've displayed in my original post. ```js function UserData( this.name, this.age, this.gender, ) {} // probably more readable / better practice in usage, works just as well: function UserData({ name: this.name, age: this.age, gender: this.gender, }) {} ``` While I'm on that subject, thoughts on this being equivalent to the above? ```js function UserData({ this.name, this.age, this.gender, }) {} ``` I don't really like it because it looks _very_ similar to the approach with named arguments; the braces are easy to miss, but it's still very succinct. > How about `own` keyword? It might work with public and private fields, > and seems more elegant (because of destructuring we have a lot of symbols > in the paremeters declaration) I'm against piling on too many unfamiliar language constructs. Even without knowing ES2015+, the semantics of `this.*` assigns in a function declaration are easily understood at a first glance, and meshes nicely with everything else available in the language as is. > More prior art, this time from C#, which shifts the burden from the > constructor to the call to it: You can set accessible properties in an > initializer after the call to the constructor: Not for this either. This is easily done with `Object.assign` and similar. ```js const obj = Object.assign(new Example(), { x: 1, y: 2 }) ```
kingdaro at gmail.com (2017-03-18T19:37:25.749Z)
> I don't see any point to having this on methods. On constructors, I > suppose it's a bit of convenience. If it's supported on constructor functions, my reasoning was that it'd only make sense for it to be supported on methods (which are also just functions). Having this syntax available for functions allows really nice, convenient data structures, and getter/setters as I've displayed in my original post. ```js function UserData( this.name, this.age, this.gender, ) {} // probably more readable / better practice in usage, works just as well: function UserData({ name: this.name, age: this.age, gender: this.gender, }) {} ``` While I'm on that subject, thoughts on this being equivalent to the above? ```js function UserData({ this.name, this.age, this.gender, }) {} ``` I don't really like it because it looks _very_ similar to the approach with named arguments; the braces are easy to miss, but it's still very succinct. > How about `own` keyword? It might work with public and private fields, and seems more elegant (because of destructuring we have a lot of symbols in the paremeters declaration) I'm against piling on too many unfamiliar language constructs. Even without knowing ES2015+, the semantics of `this.*` assigns in a function declaration are easily understood at a first glance, and meshes nicely with everything else available in the language as is. > More prior art, this time from C#, which shifts the burden from the > constructor to the call to it: You can set accessible properties in an > initializer after the call to the constructor: Not for this either. This is easily done with `Object.assign` and similar. ```js const obj = Object.assign(new Example(), { x: 1, y: 2 }) ```
kingdaro at gmail.com (2017-03-18T19:37:07.056Z)
> I don't see any point to having this on methods. On constructors, I > suppose it's a bit of convenience. If it's supported on constructor functions, my reasoning was that it'd only make sense for it to be supported on methods (which are also just functions). Having this syntax available for functions allows really nice, convenient data structures, and getter/setters as I've displayed in my original post. ```js function UserData( this.name, this.age, this.gender, ) {} // probably more readable / better practice in usage, works just as well: function UserData({ name: this.name, age: this.age, gender: this.gender, }) {} ``` While I'm on that subject, thoughts on this being equivalent to the above? ```js function UserData({ this.name, this.age, this.gender, }) {} ``` I don't really like it because it looks _very_ similar to the approach with named arguments; the braces are easy to miss, but it's still very succinct. > How about `own` keyword? It might work with public and private fields, and seems more elegant (because of destructuring we have a lot of symbols in the paremeters declaration) I'm against piling on too many unfamiliar language constructs. Even without knowing ES2015+, the semantics of `this.*` assigns in a function declaration are easily understood at a first glance, and meshes nicely with everything else available in the language as is. > More prior art, this time from C#, which shifts the burden from the constructor to the call to it: You can set accessible properties in an initializer after the call to the constructor: Not for this either. This is easily done with `Object.assign` and similar. ```js const obj = Object.assign(new Example(), { x: 1, y: 2 }) ```