Pass a JavaScript function as parameter

前端 未结 13 1699
星月不相逢
星月不相逢 2020-11-22 07:06

How do I pass a function as a parameter without the function executing in the \"parent\" function or using eval()? (Since I\'ve read that it\'s insecure.)

13条回答
  •  余生分开走
    2020-11-22 07:55

    Some time when you need to deal with event handler so need to pass event too as an argument , most of the modern library like react, angular might need this.

    I need to override OnSubmit function(function from third party library) with some custom validation on reactjs and I passed the function and event both like below

    ORIGINALLY

        
    

    MADE A NEW FUNCTION upload and called passed onSubmit and event as arguments

    
    
    upload(event,fn){
      //custom codes are done here
      fn(event);
    }
    

提交回复
热议问题