Can I name a JavaScript function and execute it immediately?

前端 未结 8 1738
谎友^
谎友^ 2020-11-28 04:04

I have quite a few of these:

function addEventsAndStuff() {
  // bla bla
}
addEventsAndStuff();

function sendStuffToServer() {
  // send stuff
  // get HTML         


        
8条回答
  •  渐次进展
    2020-11-28 04:31

    If you want to create a function and execute immediately -

    // this will create as well as execute the function a()
    (a=function a() {alert("test");})();
    
    // this will execute the function a() i.e. alert("test")
    a();
    

提交回复
热议问题