數(shù)據(jù)蛙數(shù)據(jù)分析2022就業(yè)班
上述中的 this
會打印出什么呢?
let obj = {
? ?init() {
? ? ? ?console.log( this ) ?// 2. ?this === obj
? ? ? ?let prop = {
? ? ? ? ? ?init: () => {
? ? ? ? ? ? ? ?console.log( this ) ?// 4. this === prop 同級 this ==> this === obj
? ? ? ? ? ?},
? ? ? ? ? ?bind() {
? ? ? ? ? ? ? ?console.log( this ) ?// 6. this === prop
? ? ? ? ? ?}
? ? ? ?}
? ? ? ?prop.init() ?// 3. init() 是箭頭函數(shù) ==> prop.init.call( prop 同級 this )
? ? ? ?prop.bind() ?// 5. bind 不是箭頭函數(shù) ==> prop.bind.call( prop )
? ?}}obj.init() ?// 1. ?=== obj.init.call( obj )
標(biāo)簽: