How do undefined or remove a javascript function?

后端 未结 5 978
不知归路
不知归路 2021-02-06 00:05

I defined a global Javascript function:

  function resizeDashBoardGridTable(gridID){
  var table = document.getElementById(\'treegrid_\'+gridID);
        .....
          


        
5条回答
  •  闹比i
    闹比i (楼主)
    2021-02-06 00:27

    If the functions needs to be called 1 time you use an anonymous self invoking function like this:

    (function test(){
        console.log('yay i'm anonymous');
    })();
    

    If you have to call the function multiple times you store it into a var and set it to null when you're done.

    Note: You don't have to name an anonymous function like I named it test. You can also use it like this:

    (function(){
        console.log('test');
    })();
    

    The reason I do name my anonymous functions is for extra readability.

提交回复
热议问题