T.J. Crowder (2017-03-18T19:12:56.000Z)
tj.crowder at farsightsoftware.com (2017-03-18T19:21:32.159Z)
On Sat, Mar 18, 2017 at 6:04 PM, Jordan Harband <ljharb at gmail.com> wrote: > I'd think with the advent of private fields a much more > common (and better) use case would not involve creating > publicly visible properties - how might that work? > > Perhaps this: > ```js > class Foo { > constructor(#x, #y) { } > } > ``` It seems strange to me to advertise your private properties like that, but of course, the source is right there anyway... Worth noting the TypeScript prior art: ```js // (TypeScript) class Example { constructor(public x, public y) { } } const e = new Example(1, 2); console.log(e.x); // 1 console.log(e.y); // 2 ``` Note the access modifier on the parameters. (`private` works as well.) So quite similar to Jordan's `constructor(#x, #y)` for private data (if that horrible `#` does in fact happen in the private data proposal), and to "just nobody"'s `constructor(this.x, this.y)` for instance properties. I don't see any point to having this on methods. On constructors, I suppose it's a bit of convenience. 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: ```c# var obj = new Example() { x = 1, y = 2}; Console.WriteLine(obj.x); // 1 Console.WriteLine(obj.y); // 2 ``` -- T.J. Crowder