Los Angeles, CA

How do I convert an existing callback API to promises?

How do I convert an existing callback API to promises?

function isIt(){
   let someOp = true
        
        if(someOp) 
           return 'its true'
        else 
           return 'no bueno'
}

//becomes

function isIt() {
    return new Promise(function(resolve, reject) {
        let someOp = true
        
        if(someOp) 
           resolve('its true')
        else 
           reject('no bueno')
    });
}
Facebook Comments