SOURCE

function bind(fn, target, ...arg) {
  let context = target || window;
  if(typeof fn !== 'function') {
    throw Error('绑定的必须是一个函数!')
  }
  
  return function() {
    return fn.call(context, ...arg)
  }
}

const b = {
  name: 'mike',
  sayName: function() {
    console.log(this.name)
  }
}
b.sayName();

bind(b.sayName, {name: 'pick'})();

function call(fn, target, ...args) {
  if(typeof target === 'object' ) {
    
  }
  let context = target || window;
  if(typeof fn !== 'function') {
    throw Error('绑定的必须是一个函数!')
  }
  
  const name = fn.name;
 	context[name] = fn;
  let res = context[name](args);
  delete context[name];
  return res;
}
console.log(call(b.sayName, {name: 'cc'}))

console 命令行工具 X clear

                    
>
console