Pass a JavaScript function as parameter

前端 未结 13 1789
星月不相逢
星月不相逢 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 08:00

    Here it's another approach :

    function a(first,second)    
    {        
    return (second)(first);           
    }     
    
    a('Hello',function(e){alert(e+ ' world!');}); //=> Hello world     
    

提交回复
热议问题