분류
javascript
Javascript 30초 Snippet - Type : isPromiseLike
본문
객체가 약속처럼 보이면 true를, 그렇지 않으면 false를 반환합니다.
https://github.com/30-seconds/30-seconds-of-code
객체가 null이 아니고 typeof가 객체 또는 함수와 일치하는지 그리고 함수 인 .then 속성이 있는지 확인하십시오.
const isPromiseLike = obj => obj !== null && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function';
ex)
isPromiseLike({ then: function() { return ''; } }); // true isPromiseLike(null); // false isPromiseLike({}); // false
- 이전글Javascript 30초 Snippet - Type : isString 19.11.25
- 다음글Javascript 30초 Snippet - Type : isPrimitive 19.11.25