Update and rename isPromise.md to isPromiseLike.md
This commit is contained in:
@ -1,16 +1,16 @@
|
|||||||
### isPromise
|
### isPromiseLike
|
||||||
|
|
||||||
Returns `true` if an object looks like a [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise), `false` otherwise.
|
Returns `true` if an object looks like a [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise), `false` otherwise.
|
||||||
|
|
||||||
Check if the object is not `null`, its `typeof` matches either `object` or `function` and if it has a `.then` property, which is also a `function`.
|
Check if the object is not `null`, its `typeof` matches either `object` or `function` and if it has a `.then` property, which is also a `function`.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const isPromise = obj =>
|
const isPromiseLike = obj =>
|
||||||
obj !== null && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function';
|
obj !== null && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function';
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
isPromise({then:function () {return ''}}); // true
|
isPromiseLike({then:function () {return ''}}); // true
|
||||||
isPromise(null); // false
|
isPromiseLike(null); // false
|
||||||
isPromise({}); // false
|
isPromiseLike({}); // false
|
||||||
```
|
```
|
||||||
Reference in New Issue
Block a user