#thenable
是一个对象或者函数。
thenable 对象的作用: 使promise的实现更具有通用性
识别
thenable
或行为类似Promise对象可以根据其是否具有then(...)
方法来判断,这叫类型检查(鸭式辩型)。
thenable
的鸭式类型检测:
if(p !==null &&
(
typeof p === 'object' ||
typeof p === 'function'
)&&
typeof p.then === 'function'
){
//thenable
}else{
//非thenable
}
轻汗微微透碧纨。