What is `this` inside a new-invoked generator?

2015-03-23 Thread Axel Rauschmayer
Question: what does the following code snippet log in the last line?

```js
function* gen() {
yield this;
}
let genObj = new gen();
let [_this] = genObj;
console.log(_this === genObj); // ???
```

I’m finding three answers:

1. The spec says [1] that any reference to `this` in a generator invoked via 
`new` causes a `ReferenceError`.

2. Firefox logs `false` for the code snippet.

3. A year ago, Allen stated [2] that if you invoke a generator function via 
`new`, `this` points to the generator object. On other words, the code snippet 
would log `true`.


[1] 
https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generator-function-definitions-runtime-semantics-evaluatebody
[2] 
https://esdiscuss.org/topic/reason-why-generators-do-not-have-references-to-themselves#content-8

-- 
Dr. Axel Rauschmayer
a...@rauschma.de
rauschma.de

___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: What is `this` inside a new-invoked generator?

2015-03-23 Thread André Bargull

Question: what does the following code snippet log in the last line?

```js
function* gen() {
 yield this;
}
let genObj = new gen();
let [_this] = genObj;
console.log(_this === genObj); // ???
```

I’m finding three answers:

1. The spec says [1] that any reference to `this` in a generator invoked via 
`new` causes a `ReferenceError`.

2. Firefox logs `false` for the code snippet.

3. A year ago, Allen stated [2] that if you invoke a generator function via 
`new`, `this` points to the generator object. On other words, the code snippet 
would log `true`.


It's a ReferenceError. Future editions may add a meta property to make it possible to retrieve the 
current generator object (https://bugs.ecmascript.org/show_bug.cgi?id=3626).

___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss