JSFiddle - React, Tailwind, and code Playground

by vinodlouis

JavaScript

class MyPromise{
   
     constructor(fn){
         this.fn = fn
         this._s = null;
         this._e = null;
         this.resolve = this.resolve.bind(this);
        
         (async () => {
        	await this.fn(this.resolve,this.reject);
           this.then = this.then.bind(this);

    		})();
        
         
      
     }
    
    resolve(p){
        this._s = p
    }
    
    reject(e){
        this._e = e
    }
    
    then(success,error){
        //console.log("ONE",this,success,error);
       if(this._s){
       	success(this._s)
       }
       
       
       if(this._e){
       	error(this._e)
       }
       
       
    }
 }

var g = new MyPromise((a,b)=>{
console.log('hello');

setTimeout(()=>console.log(12345),1000)
 
a('12');
}).then((dt)=>{

console.log(dt,'qwe')
},(err)=>{
})