SOURCE

Function.prototype.myBind = function (context,...args){
    if(typeof this!=='function'){
        throw new TypeError('Error')
    }
    const _this = this;
    return function F(...args2){
        if(this instanceof F){
            return new _this(args,...args2)
        }
        return _this.apply(context,[...args,...args2])
    }
}
function greet(greeting,age) {
  console.log(`${greeting} ${age}, ${this.name}`);
}

const person = { name: 'Alice' };

// 使用 myCall 来调用 greet 函数,并指定上下文对象为 person
const age = greet.myBind(person, 'Hello');
age(12)
console 命令行工具 X clear

                    
>
console