I played with generators in Nodejs v0.11.2 and I'm wondering how I can check that argument to my function is generator function.
I found this way typeof f === 'function' && Object.getPrototypeOf(f) !== Object.getPrototypeOf(Function)
but I'm not sure if this is good (and working in future) way.
What is your opinion about this issue?
In the latest version of nodejs (I verified with v0.11.12) you can check if the constructor name is equal to GeneratorFunction
. I don't know what version this came out in but it works.
function isGenerator(fn) {
return fn.constructor.name === 'GeneratorFunction';
}