Add isGeneratorFunction

This commit is contained in:
Angelos Chalaris
2020-08-07 15:40:38 +03:00
parent 4cf93754d2
commit 338bce1ed7

View File

@ -0,0 +1,18 @@
---
title: isGeneratorFunction
tags: 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]'`.
```js
const isGeneratorFunction = val =>
Object.prototype.toString.call(val) === '[object GeneratorFunction]';
```
```js
isGeneratorFunction(function() {}); // false
isGeneratorFunction(function*() {}); // true
```