面试题-----闭包2

1.

var age=100;
function test(){
this.age=50;
return function(){
return this.age;
}
}
var m=new test();//new出来的test实例对象,添加age属性并且赋值为50,m接收return返回的function(){return this.age};,匿名函数return回去的this.age,匿名函数没有age属性,所以结果为undefined

//可以理解为此时的m其实是等于function(){return this.age};
console.log(m.age);//undefined

原文地址:https://www.cnblogs.com/luxiaoxiao/p/6066944.html