this总是指向一个对象,具体指向哪个对象是在运行时基于函数的执行环境动态绑定的,不是函数声明时候的环境
如果函数作为对象的方法调用时,函数里面的this指向该对象

非严格模式下如果函数不作为对象的方法调用,只作为普通函数调用时,函数里面的this指向全局对象,在浏览器中,全局对象是window

严格模式下则this为undefined

当函数作为构造器调用时,函数里面的this指向,通过new 函数返回来的对象。假如这个函数显示的返回了一个object类型的对象,那么new 函数的结果就是这个对象,即this指向这个对象

网友评论