You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
constname='global name'constsay=(first,last)=>{console.info(first,this.name,last)}constobj={name: 'obj name'}say.call(obj,'one','two')// one global name two => 并未修改this的指向
The text was updated successfully, but these errors were encountered:
this
this
, 定义期无法确定this
this
被禁止指向全局对象this
指向window
this == window
// truethis
指向被new
出来的对象call
,apply
或者bind
的调用, 当一个函数被call/apply/bind
调用时,this
的值就是传进去的对象DOM event
在一个HTML DOM
事件处理程序中,this
始终指向这个处理程序绑定的HTML DOM
节点this
: 箭头函数完全修复了this
的指向,this
总是指向词法作用域
, 也就是外层调用者obj
, 由于this
在箭头函数中已经按照词法作用域绑定了, 所以用call/apply
调用箭头函数时, 无法对this
进行绑定, 也就是说传入的第一个参数将被忽略.The text was updated successfully, but these errors were encountered: