1.普通函数
function fn(){
console.log(this)
}
//fn() fn.call()
//this指向window,fn()完全写法为window.fn()
2.对象的方法
var o = {
sayHi:function(){
console.log(this)
}
}
o.sayHi()
//this指向对象o(函数调用者)
3.构造函数
function Star(){}
//原型对象里的this也指向dm这个实例对象
Star.prototype.sing=function(){
}
//函数调用
new Star()
//this指向实例对象dm
var dm = new Star()
4.绑定事件函数
//点击按钮触发
btn.onclick=function(){
console.log(this)
}
//this指向函数调用者btn这个按钮对象
5.定时器函数
//自动一秒钟调用一次
setInterval(function(){},1000)
//this指向window,上面完整写法为window.setInterval
6.立即执行函数
(function(){
console.log('人生巅峰')
}())
//this指向window