JavaScript中new函数学习

mac2022-06-30  26

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

转载于:https://www.cnblogs.com/-gap/archive/2012/08/24/2654311.html

最新回复(0)