Generator getter method

Mohsen Azimi me at azimi.me
Tue Nov 10 19:27:57 UTC 2015


Can we allow generator getter methods?

Here is an example use case:

```
let rectangle = {
  start: {x: 1, y: 5},
  width: 2,
  height: 3,

  *getCorners() {
    let {x: startX, y: startY} = this.start;
    yield this.start;
    yield {x: startX + this.width, y: startY};
    yield {x: startX + this.width, y: startY + this.height};
    yield {x: startX, y: startY + this.height}
  }
}

for (let corner of rectangle.getCorners()) {
  console.log(corner);
}
```

I'm proposing to allow  `get coreners* () { ...` (a generator getter
method) so the for..of loop can be written like this:

```
for (let corner of rectangle.corners) {
  console.log(corner);
}
```

Which seems cleaner
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20151110/55d4692a/attachment.html>


More information about the es-discuss mailing list