// Does not work with `new (funcA.bind(thisArg, args))`
Function.prototype.bind = function (context, ...args) {
if (typeof this !== 'function') {
// closest thing possible to the ECMAScript 5
// internal IsCallable function
throw new TypeError('Function.prototype.bind - ' +
'what is trying to be bound is not callable');
}
let self = this
return function () {
// 每次合并参数, 并返回函数(尚未执行)
return self.apply(context, [...arguments, ...args]);
}
}