其他分享
首页 > 其他分享> > 前端入门知识点笔记本

前端入门知识点笔记本

作者:互联网

1.

call()、bind()、apply()的用法,改变this的指向,区别在于
f.call(obj, arg1, arg2...),
f.bind(obj, arg1, arg2,...)(),
f.apply(obj, [arg1, arg2, .])

Example:封装函数 f,使 f 的 this 指向指定的对象

(1)apply()

function bindThis(f, oTarget) {
 return function() {
     return f.apply(oTarget, arguments)
    }
}

 

(2)bind()

function bindThis(f, oTarget) {
 return f.bind(oTarget)
}

 

(3)call()

function bindThis(f, oTarget) {
 return function() {
     return f.call(oTarget, ...arguments)
    }
}

 

标签:function,知识点,return,入门,bind,笔记本,call,oTarget,apply
来源: https://www.cnblogs.com/yueyiviolet/p/15076794.html