class Promise{
cbs=[];
value='';
status='pending'
constructor(invoke){
invoke(this.resolve.bind(this));
}
then(call){
console.log('then')
if(this.status==='pending'){
this.cbs.push(call);
}else{
call(this.value)
}
return this;
}
resolve(value){
setTimeout(()=>{
this.status='fulfilled';
this.value=value;
console.log('resolve')
this.cbs.forEach(c=>c(value))
},0)
}
}
new Promise((resolve)=>{
resolve('promise');
}).then((res)=>{
console.log(res,'then');
}).then((res)=>{
console.log(res,'then1');
})
console