How do undefined or remove a javascript function?

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

I defined a global Javascript function:

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


        
5条回答
  •  你的背包
    2021-02-06 00:17

    how about using a var?

    // define it
    var myFunction = function(a,b,c){
      console.log('Version one: ' + [a,b,c].join(','));
    }
    myFunction('foo','bar','foobar'); // output: Version one: foo,bar,foobar
    
    // remove it
    myFunction = null;
    try { myFunction(); console.log('myFunction exists'); }
    catch (e) { console.log('myFunction does not exist'); }
    
    // re-define it
    myFunction = function(d,e,f){
      console.log('Version two: ' + [d,e,f].join(','));
    }
    myFunction('foo','bar','foobar'); // output: Version two: foo,bar,foobar
    

    OUTPUT:

    [10:43:24.437] Version one: foo,bar,foobar
    [10:43:24.439] myFunction does not exist
    [10:43:24.440] Version two: foo,bar,foobar
    

提交回复
热议问题