js function as a parameter

Parameters js function, the function can be passed as a parameter

example:

       var Fn = (a) => {
             // if this parameter is a function, then this function is performed, or the value of a print 
            IF ( typeof a === "function" ) {
                a();
            }else{
                console.log(a)
            }
        }
      
        fn(test(2))
       
        function test(a) {
            console.log(a)
        }

Guess you like

Origin www.cnblogs.com/luguankun/p/12041759.html