function如何作为另一个function的缺省参数

解决方案 »

  1.   

    function hello(text,fn){
    alert(text);
    if(fn){ //if(arguments.length==2)
    fn();
    }
    }
    hello("word");
    这样??
      

  2.   


    function(text,fn){
        alert(text);
        fn && Object.prototype.toString.apply(fn)==='[object Function]' && fn();
    }hello('world');
      

  3.   


    function hello(text,fn){
        alert(text);
        fn && Object.prototype.toString.apply(fn)==='[object Function]' && fn();
    }
    hello('world');