ES5 寫法
Function.prototype.myBind = function(context) {
var _this = this;
var args = Array.prototype.slice.call(arguments, 1);
return function() {
var args2 = args.concat(Array.prototype.slice.call(arguments));
_this.apply(context, args);
}
}
ES6 寫法
Function.prototype.myBind = function(context, ...args1) {
return (...args2) => {
this.apply(context, [...args1, ...args2]);
}
}