1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| const foo = { bar:10, fn:function(){ console.log(this.bar) console.log(this) } } let fn1 = foo.fn fn1()
const o1 = { text:'o1', fn:function(){ console.log('o1fn_this',this) return this.text } } const o2 = { text:'o2', fn:function(){ console.log('o2fn_this',this) return o1.fn() } }
const o3 = { text:'o3', fn:function(){ console.log('o3fn_this',this) let fn = o1.fn return fn() } }
console.log('o1',o1.fn()) console.log('o2',o2.fn()) console.log('o3',o3.fn())
|