How to tell function and generator function apart?

Damian Senn damian.senn at adfinis-sygroup.ch
Tue Mar 3 17:07:08 UTC 2015


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



More information about the es-discuss mailing list