var a=11
function test1(){
this.a=22;
let b=function(){
console.log(this.a);
};
b();
}
var x=new test1(); //11这个函数我的理解是,this不是指向调用环境中值吗。所以b函数应该在test1里调用,应该是22才对啊...请问是什么问题
2 回答
![?](http://img1.sycdn.imooc.com/54584f8f00019fc002200220-100-100.jpg)
胡子哥哥
TA贡献1825条经验 获得超6个赞
this指向调用者或者window啊,换成箭头函数是你想要得样子
var a=11 function test1(){ this.a=22; var b=()=>{ console.log(this.a); }; b(); }
添加回答
举报
0/150
提交
取消