Function.prototype.bind = function(context) { context = context || window; let that = this; let args = Array.prototype.slice.call(arguments, 1); let fn = function() { let fnArgs = Array.prototype.slice.call(arguments); return that.apply(this instanceof that ? this : context, args.concat(fnArgs)); }; fn.prototype = Object.create(this.prototype); return fn; }