javascript 函数返回值的问题,请高手解答

function aFun(){

    function _(arg){

        this.arg = arg;

    }


    _.prototype.testFun = function(){

        console.log('this is prototype testFun')

    };


    _.testFun2 = function(){

        console.log('this is testFunc2');

    }


    return _;

};


var afun = new aFun('123');

console.log(afun instanceof aFun)

afun.testFun2(); //可以调用

afun.testFun(); //不是在原型链上么?,为啥不可以调用???,



var aFun2 = (function (){

    function _(arg){

        this.arg = arg;

    }


    _.prototype.testFun = function(){

        console.log('this is prototype testFun')

    };

    _.testFun2 = function(){

        console.log('this is testFunc2');

    }


    return _;

})();


var afun2 = new aFun2('ddd');

console.log(afun2 instanceof aFun2)

afun2.testFun2(); //不可以调用,为啥?

afun2.testFun(); //可以调用,为啥可以?(我要疯了)



fshang
浏览 96回答 0
0回答
打开App,查看更多内容
随时随地看视频慕课网APP