new 操作符

;(function(){
    var test=function(){
        var tem={};
        tem.a=1;
        return tem;
    }
    var r=new test();//{a:1}
    console.log(r);
    console.log(r.__proto__===test.prototype);false;
    test=function(){
        var me=this;
        me.a=1;
        return function(){}
    }
    r=new test();
    console.log(r.__proto__===test.prototype);//true
    var myNew=function(handler){
        var tem={};
        tem.__proto__=handler.prototype;
        if(typeof handler.call(tem)!=="object"&&handler.call(tem)!=="function")
            return tem;
        return handler.call(tem);
    }
})()

 

posted on 2018-10-28 13:50  偏灬爱  阅读(116)  评论(0编辑  收藏  举报

导航