摘要: 避免this出现歧义 1 function Aaa() 2 { 3 var _this=this; 4 this.a=12; //当前的对象的this 5 setInterval(function (){ //有定时器的时候,会出现this的误解问题 6 _this.show(); //把this存为一个变量,传递进来,因为this代表的不一样,所以定时器里面的this需要是外层的this,也就是Aaa 7 }, 1000); 8 } 9 10 Aaa.prototype.show=function ()... 阅读全文
posted @ 2013-06-17 21:59 Paxster 阅读(266) 评论(0) 推荐(0) 编辑
摘要: 构造函数里的this,外面的new 1 <script> 2 //用工厂方式构造对象 3 function createPerson(name, sex) //构造函数 4 { 5 //假想的系统内部工作流程 6 //var this=new Object(); 7 this.name=name; 8 this.sex=sex; 9 10 this.showName=function ()11 {12 alert('我的名字叫:'+this.name);13 };14 this.showSex=fun... 阅读全文
posted @ 2013-06-17 12:15 Paxster 阅读(190) 评论(0) 推荐(0) 编辑