Pass a JavaScript function as parameter

前端 未结 13 1502
星月不相逢
星月不相逢 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:07

    In fact, seems like a bit complicated, is not.

    get method as a parameter:

     function JS_method(_callBack) { 
    
               _callBack("called");  
    
            }
    

    You can give as a parameter method:

        JS_method(function (d) {
               //Finally this will work.
               alert(d)
        });
    

提交回复
热议问题