After the resolve function is completed, (1) the state of the promise changes from Pending to depressing. (2) The result value of the object is modified

Reject (1) The state of the Promise changes from Pending to Rejected (2) The result value of the reject object is modified

function Promise(executor){
    // Resolve and reject are functions
    
    // Add attributes
    this.PromiseState = "pending";
    this.PromiseResult = null
    
    const self = this;
    / / resolve function
    function resolve(data){
        // (1) Change the state of the object
        // this.promisestate // This is window because resolve is called directly
        self.PromiseState = 'fulfilled'
        // (2) Set the object result value
        self.PromiseResult = data
    }
    
    / / reject function
    function reject(data){
       // (1) Change the state of the object
        self.PromiseState = 'rejected'
        // (2) Set the object result value
        self.PromiseResult = data
    }
    
    // Call the executor function synchronously
    executor(resolve,reject) 
}

// Add the then method
Promise.prototype.then = function(onResolved,onRejected){}Copy the code