1、普通函数(this 指向 window)
function fn(){
console.log('认识的巅峰');
}
fn();/fn.call();
2、对象的方法(this 指向的是对象 o)
var o = {
sayHi: function(){
console.log('认识的巅峰');
}
}
o.sayHi();
3、构造函数(this 指向实例对象/原型对象里面的this也指向的是实例对象)
function Star(){};
new Star();
4、绑定时间函数(this 指向函数的调用着 btn)
btn.onclick = function(){};
//点击了按钮就可以调用这个函数
5、定时器函数(this 指向 window)
window.setInterval(function(){},1000);
//这个函数是定时器自动1秒钟调用一次
6、立即执行函数(this 指向 window)
(function(){
console.log('认识的巅峰');
})();
//立即执行函数是自动调用