Combined is snippets into a generic one

This commit is contained in:
Angelos Chalaris
2018-01-17 21:23:46 +02:00
parent 6921a9387b
commit 4feb68e848
10 changed files with 20 additions and 112 deletions

19
snippets/is.md Normal file
View File

@ -0,0 +1,19 @@
### is
Checks if the provided value is of the specified type.
Use the `instanceof` operator to check if the provided value is of the specified `type`.
```js
const is = (type, val) => val instanceof type;
```
```js
is(Array,[1]); // true
is(ArrayBuffer, new ArrayBuffer()); // true
is(Map, new Map()); // true
is(RegExp, /./g); // true
is(Set, new Set()); // true
is(WeakMap, new WeakMap()); // true
is(WeakSet, new WeakSet()); // true
```