How to tell function and generator function apart?

Jordan Harband ljharb at gmail.com
Tue Mar 3 17:08:00 UTC 2015


It's not quite that simple due to variations across different engines, but
I've got a module https://www.npmjs.com/package/is-generator-function that
covers it.

On Tue, Mar 3, 2015 at 9:07 AM, Damian Senn <damian.senn at adfinis-sygroup.ch>
wrote:

> Hi Gui
>
> On 03/03/2015 05:41 PM, Guilherme Souza wrote:
>
>> Hi all,
>>
>> I was wondering how one could check if a given function is a generator
>> function, is a cross-realm way:
>>
>
> I'm detecting this with the following piece of code:
>
>   if ((function*(){}).constructor.name == 'GeneratorFunction')) {
>     // is generator function
>   }
>
> or something like:
>
>   function isGenerator(fn) {
>     return fn && fn.constructor && fn.constructor.name ==
> 'GeneratorFunction'
>   }
>
> Regards
> Damian
>
> --
> Adfinis SyGroup AG
> Damian Senn, Software Engineer
>
> Keltenstrasse 98 | CH-3018 Bern
> Tel. 031 550 31 11
>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150303/62a70a87/attachment.html>


More information about the es-discuss mailing list