1、this指向undefined
es6的严格模式中 如果调用函数中的this或者顶层的this将会被指向undefined
function fn(){
console.log(this);
}
fn();
console.log(this);
this指向window
a、非严格模式中函数或者顶层中调用this
b、回调函数中默认this指向window
回调函数具体的定义为:函数A作为参数(函数引用)传递到另一个函数B中,并且这个函数B执行函数A。我们就说函数A叫做回调函数。如果没有名称(函数表达式),就叫做匿名回调函数
var obj = {
a:1,
b:function(){
console.log(this);
},
c:function(f){
// f();
// arguments[0]0;//arguments
}
}
obj.b();//obj
obj.c(obj.b);//window
c、当使用call apply bind 如果带入的第一个参数是null或者undefined时 this默认指window
3、this指向上下文环境中的this
a、 箭头函数
var obj={
a:function(){
setTimeout(()=>{
this.b();//this就是当前箭头函数外的上下文中this指向
//