javascript - check if function is a generator -


i played generators in nodejs v0.11.2 , i'm wondering how can check argument function generator function.

i found way typeof f === 'function' && object.getprototypeof(f) !== object.getprototypeof(function) i'm not sure if (and working in future) way.

what opinion issue?

we talked in tc39 face-to-face meetings , deliberate don't expose way detect whether function generator or not. reason function can return iterable object not matter if function or generator function.

var iterator = symbol.iterator;  function notagenerator() {   var  count = 0;   return {     [iterator]: function() {       return this;     },     next: function() {       return {value: count++, done: false};     }   } }  function* agenerator() {   var count = 0;   while (true) {     yield count++;   } } 

these 2 behave identical (minus .throw() can added too)


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -