Hi all,

I was wondering how one could check if a given function is a generator
function, is a cross-realm way:

```
let f = function(){}
let g = function*(){}

typeof f === typeof g // 'function'

f instanceof Function // true, but only in the same Realm
g instanceof Function // true, but again only in the same Realm

let GeneratorFunction = Object.getPrototypeOf(function*(){}).constructor
f instanceof GeneratorFunction // false
g instanceof GeneratorFunction // true, but only in the same Realm

// This works, but relies on Function.prototype being a function itself.
typeof Object.getPrototypeOf(f) // 'function'
typeof Object.getPrototypeOf(g) // 'object'
```

So what is the recommended way to do this type of check?
Would something like `Array.isArray` for generator functions be helpful?

Regards,
Gui
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to