Can I name a JavaScript function and execute it immediately?

前端 未结 8 1737
谎友^
谎友^ 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:26

    You might want to create a helper function like this:

    function defineAndRun(name, func) {
        window[name] = func;
        func();
    }
    
    defineAndRun('addEventsAndStuff', function() {
        alert('oele');
    });
    

提交回复
热议问题