diff --git a/README.md b/README.md index cd1c4ade7..249221388 100644 --- a/README.md +++ b/README.md @@ -4442,10 +4442,7 @@ Return a `function` that uses `Function.apply()` to apply the given `context` to Use `Array.concat()` to prepend any additional supplied parameters to the arguments. ```js -const bind = (fn, context, ...args) => - function() { - return fn.apply(context, args.concat(...arguments)); - }; +const bind = (fn, context, ...boundArgs) => (...args) => fn.apply(context, [...boundArgs, ...args]); ```
diff --git a/docs/function.html b/docs/function.html index 079064cb1..a74ab6151 100644 --- a/docs/function.html +++ b/docs/function.html @@ -90,10 +90,7 @@ return document.querySelectorAll(selector); }, '>_>'); if (elements instanceof Error) elements = []; // elements = [] -

bind

Creates a function that invokes fn with a given context, optionally adding any additional supplied parameters to the beginning of the arguments.

Return a function that uses Function.apply() to apply the given context to fn. Use Array.concat() to prepend any additional supplied parameters to the arguments.

const bind = (fn, context, ...args) =>
-  function() {
-    return fn.apply(context, args.concat(...arguments));
-  };
+

bind

Creates a function that invokes fn with a given context, optionally adding any additional supplied parameters to the beginning of the arguments.

Return a function that uses Function.apply() to apply the given context to fn. Use Array.concat() to prepend any additional supplied parameters to the arguments.

const bind = (fn, context, ...boundArgs) => (...args) => fn.apply(context, [...boundArgs, ...args]);
 
function greet(greeting, punctuation) {
   return greeting + ' ' + this.user + punctuation;
 }