无意中看到一段大神的代码,大体结构如下
function handleThenable(promise, value) {
var resolved;
try {
if (promise === value)
{ throw new TypeError('A promises callback cannot return that same promise.'); }
if (value && (typeof value === 'function' || typeof value === 'object'))
{
var then = value.then; // then should be retrived only once
if (typeof then === 'function')
{
then.call(value, function(val){
if (!resolved)
{
resolved = true;
if (value !== val)
{ resolve(promise, val); }
else
{ fulfill(promise, val); }
}
}, function(reason){
if (!resolved)
{
resolved = true;
reject(promise, reason);
}
});
return true;
}
}
} catch (e) {
if (!resolved)
{ reject(promise, e); }
return true;
}
return false;
}
我的问题 这个函数handleThenable什么时候会 return false;
格式化下就清晰了,不满足圈中的2个if条件返回false