About how to write some JS

for example, if you want to write a callback, you can use promise:

 function a(){
    return new Promise(function(res,rej){
        res()
    }) 
 }
 
 a().then()

but now I want the code to run directly in the browser instead of going through webpack (ES6 to 5).

then use

var a = function(x){x();}
a(function(){
    console.log("")
})
//
Mar.29,2021

you can use es5. You can use polyfill to support promise,. There is no need to use callback writing, and the compatibility is good


.

now most modern browsers support Promise (after all, some browsers' API returns this), and you can also use some compatible libraries to support it.

as for your second way of writing, which is the most traditional callback , all I can think of is the pointing control problem of this .


there will be no problem, please rest assured to use it.

Menu