Skip to content

Latest commit

 

History

History
18 lines (14 loc) · 460 Bytes

isGeneratorFunction.md

File metadata and controls

18 lines (14 loc) · 460 Bytes
title tags
isGeneratorFunction
type,function,intermediate

Checks if the given argument is a generator function.

  • Use Object.prototype.toString() and Function.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