InterviewMap / CS-Interview-Knowledge-Map

Build the best interview map. The current content includes JS, network, browser related, performance optimization, security, framework, Git, data structure, algorithm, etc.
https://yuchengkai.cn/docs/frontend/
18.3k stars 2.57k forks source link

Js章节 Promise实现语法错误 #192

Open eightHundreds opened 5 years ago

eightHundreds commented 5 years ago

这个

onRejected = typeof onRejected === 'function' ? onRejected : r => throw r;

改为

onRejected = typeof onRejected === 'function' ? onRejected : r => {throw r};

而且这个Promise,跑不通这个例子

console.log('script start');

setTimeout(function() {
  console.log('setTimeout');
}, 0);

new Promise((resolve) => {
    console.log('Promise')
    resolve()
}).then(function() {
  console.log('promise1');
}).then(function() {
  console.log('promise2');
});

console.log('script end');
// script start => Promise => script end => promise1 => promise2 => setTimeout