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
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
三者异同
相同点
Function
对象上的方法 ,为了改变函数体内部的this
指向this
要指向的对象,即指定函数调用上下文不同点
bind
是指定上下文,返回函数,便于稍后调用,apply
和call
则是立即调用函数并修改上下文bind()
函数会创建一个新的绑定函数(bound function,BF)
this
值和初始参数apply
传入数组this
值和参数的函数的结果call
传入参数列表call()
允许为不同的对象分配和调用属于一个对象的函数/方法call
来实现继承:写一个方法,然后让另外一个新的对象来继承它(而不是在新对象中再写一次这个方法)this
值和参数调用该函数的返回值。若该方法没有返回值,则返回undefined
参考资料
Beta Was this translation helpful? Give feedback.
All reactions