diff --git a/js2.html b/js2.html index 4c2a2b1..d880204 100644 --- a/js2.html +++ b/js2.html @@ -330,12 +330,15 @@
Question: If an older browser dont have bind function, how will you shim it
Answer: Look at the code below and use your brain.
-Function.prototype.bind = Function.prototype.bind || function(context){
- var self = this;
- return function(){
- return self.apply(context, arguments);
- };
-}
+Function.prototype.bind = Function.prototype.bind || function (context) {
+ let prevArgs = [].slice.call(arguments, 1);
+
+ return () => {
+ let currentArgs = [].slice.call(arguments);
+ let combinedArgs = [].concat(prevArgs, currentArgs);
+ return this.apply(context, combinedArgs);
+ };
+};