约束力this
约束力this
const obj = {
name : "Micheal" ,
display : () => { return
this.name ; // 'this' 指的是周围上下文} } ; let result = obj.display.bind ( obj ); console.log ( result ( )); //输出:undefined
解释:尽管bind被用来绑定this到obj,但由于display是箭头函数,所以this在词汇上仍然绑定到其原始上下文,而不是obj。因此,this.name仍然是undefined。

浙公网安备 33010602011771号