this指向
第一种:默认
var a = 1
function test () {
console.log(this.a)
}
test() // 1第二种:有爹
var a = 1
function test () {
console.log(this.a)
}
var obj = {
a: 2,
test
}
var obj0 = {
a: 3,
obj
}
obj0.obj.test()迷惑1:看起来有爹其实没有
迷惑2:settimeout
第三种:改this指向:call/apply/bind
第四种:new
第五种:箭头函数
Last updated
Was this helpful?