摘要: 简单的栗子: function(){ console.log(this.a);}var obj={ a:2 }; foo.call(obj);//2 call把foo中的this指向了obj 注意↓ "装箱" 当第一个参数传入的是:字符串类型、布尔、数字类型 这个原始值会被转换成它的对象形式 new 阅读全文
posted @ 2017-09-15 18:17 _increase 阅读(103) 评论(0) 推荐(0) 编辑
摘要: 先上代码: function foo(num){ console.log("foo:"+num); this.count++;} foo.count=0; var i; for(i=0;i<10;i++){ if(i<5){ foo(i); } } 输出 6.7.8.9 console.log(fo 阅读全文
posted @ 2017-09-15 16:55 _increase 阅读(99) 评论(0) 推荐(0) 编辑
摘要: this指向函数作用域,对也错 function foo(){ var a=2; this.bar();//this 指向window}function bar(){ console.log(this.a);//指向window } foo(); //RegereceError: a is not 阅读全文
posted @ 2017-09-15 16:54 _increase 阅读(167) 评论(0) 推荐(0) 编辑
摘要: this指向函数作用域,对也错 function foo(){ var a=2; this.bar();//this 指向window}function bar(){ console.log(this.a);//指向window } foo(); //RegereceError: a is not 阅读全文
posted @ 2017-09-15 16:41 _increase 阅读(47) 评论(0) 推荐(0) 编辑
摘要: 先上代码: function foo(num){ console.log("foo:"+num); this.count++;} foo.count=0; var i; for(i=0;i<10;i++){ if(i<5){ foo(i); } } 输出 6.7.8.9 console.log(fo 阅读全文
posted @ 2017-09-15 11:24 _increase 阅读(72) 评论(2) 推荐(0) 编辑