isGeneratorFunction
Checks if the given argument is a generator function.
- Use
Object.prototype.toString()andFunction.prototype.call()and check if the result is'[object GeneratorFunction]'.
const isGeneratorFunction = val =>
Object.prototype.toString.call(val) === '[object GeneratorFunction]';isGeneratorFunction(function() {}); // false
isGeneratorFunction(function*() {}); // true