Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I detect for Generator objects in code? #51

Closed
Raynos opened this issue Nov 2, 2013 · 4 comments
Closed

How can I detect for Generator objects in code? #51

Raynos opened this issue Nov 2, 2013 · 4 comments

Comments

@Raynos
Copy link
Contributor

Raynos commented Nov 2, 2013

Currently I use

function isGenerator(obj) {
  return obj && Object.prototype.toString.call(obj) === "[object Generator]"
}

To detect a generator object which works in harmony but not in regenerator.

Is there an or clause I can add to feature detect generator objects from regenerator or should I duck test for .next() and .throw() ?

This is similar to #48

@TooTallNate
Copy link

@Raynos We're addressing this in co with a fallback to checking constructor.name. Not bulletproof, but better than nothing...

@TooTallNate
Copy link

tj/co@1cb66b8

@Raynos
Copy link
Contributor Author

Raynos commented Nov 2, 2013

I updated my function to

function isGenerator(obj) {
  return obj && (toString.call(obj) === "[object Generator]" ||
    // this fallback is here for polyfill runtimes, like facebook/regenerator
    (obj.constructor && 'Generator' == obj.constructor.name))
}

co has done the same.

@Raynos
Copy link
Contributor Author

Raynos commented Nov 2, 2013

@TooTallNate I added the same thing

Raynos/gens@3152d13

@Raynos Raynos closed this as completed Nov 2, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants