SOURCE

// bind 相比call,返回变成一个函数
// 在回调函数中拿不到调用的方法,先存一下,const _this = this
Function.prototype.myCall = function(context){
    if(typeof context=== undefined || context === null){
        return window
    }
    const _this = this
    let args  = [...arguments].slice(1)
    return function func(){
        return _this.call(context,...args)
    }
}

let a  = {s: 'hello world!'}
function say (name){
    console.log(name,this.s)
}
console.log(say.myCall(a,'Bob','Tom')())
console 命令行工具 X clear

                    
>
console