Can I name a JavaScript function and execute it immediately?

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

    There is a good shorthand to this (not needing to declare any variables bar the assignment of the function):

    var func = (function f(a) { console.log(a); return f; })('Blammo')
    

提交回复
热议问题