JavaScript中new函数学习

var A=function(){
        this.m=10;
        return 20;
    }
    var aa=new A();
    alert(aa.m);

 

var A=function(){
        this.m="this is it";
        var that={};
        that.name="that is that";
        return that;
    }
    var o=new A();
    alert(o.m);

答案就很明显了~第一个是10 因为未返回对象,所以默认返回function对象(this指向Function)

第二个是未定义,因为返回的是对象,对象里木有m

 

转自:http://99jty.com/?p=542

posted @ 2012-08-24 15:29  时生  阅读(239)  评论(0编辑  收藏  举报