如下两个例子,一个是具名函数,一个匿名函数,为什么不同结果
var a = {
b: function() {
function a() {
console.log(this.a);
}
a();
}
};
a.b();// Uncaught TypeError: Cannot read property 'a' of undefined
var a = {
b: function b() {
function a() {
console.log(this.a);
}
a();
}
};
a.b();// undefined
匿名函数应该不会影响默认
this
,影响默认this
的是 strict mode ,是否使用了use strit
。