kingdaro at gmail.com (2017-03-18T19:36:03.403Z)
Would it be possible to have syntax like this? It's a feature supported by
other JS variants in some way (CoffeeScript, TS) that feels missing from
the spec. It's mainly useful as a convenient, terse way of setting
properties of an object directly from its arguments.
```js
class Rectangle {
constructor (this.x, this.y, this.width, this.height) {}
setPosition(this.x, this.y) {}
setSize(this.width, this.height) {}
}
// equivalent to
class Rectangle {
constructor (x, y, width, height) {
this.x = x
this.y = y
this.width = width
this.height = height
}
// ...
}
// for regular functions as well
function Rectangle (this.x, this.y, this.width, this.height) {}
```
Deconstruction and argument defaults should all work similarly.
```js
function Point([this.x, this.y]) {}
function Point({ x: this.x, y: this.y }) {}
function Point(this.x = 0, this.y = 0) {}
```
Would it be possible to have syntax like this? It's a feature supported by other JS variants in some way (CoffeeScript, TS) that feels missing from the spec. It's mainly useful as a convenient, terse way of setting properties of an object on initialization. ```js class Rectangle { constructor (this.x, this.y, this.width, this.height) {} setPosition(this.x, this.y) {} setSize(this.width, this.height) {} } // equivalent to class Rectangle { constructor (x, y, width, height) { this.x = x this.y = y this.width = width this.height = height } // ... } // for regular constructor functions as well function Rectangle (this.x, this.y, this.width, this.height) {} ``` Deconstructing and argument defaults should all work similarly ```js function Point({ x: this.x, y: this.y }) {} function Point(this.x = 0, this.y = 0) {} function Point([this.x, this.y]) {} ``` -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20170318/254c9729/attachment.html>