promise

 simply to handle callback hell


 function multiply(h){

    return new Promise(function(resolve,reject){
        setTimeout(()=>{
            resolve(h*2)
        },2000)
    })
};


function add(a,b){
    return new Promise(function(resolve,reject){
        setTimeout(()=>{
            console.log("hello")
            resolve(a+b)
        },2000)
    })
};
function show(ok){
    console.log("sfhljl")
    console.log(ok)
}


add(10,20)
.then((add)=>multiply(add))
.then((zz)=>show(zz));


console.log("end")

Comments