diff --git a/README.md b/README.md index 49895db9e..1b93c9293 100644 --- a/README.md +++ b/README.md @@ -5319,10 +5319,12 @@ Use `Array.forEach()` to return a `function` that uses `Function.apply()` to app ```js const bindAll = (obj, ...fns) => fns.forEach( - fn => + fn => ( + (f = obj[fn]), (obj[fn] = function() { - return fn.apply(obj); + return f.apply(obj); }) + ) ); ``` diff --git a/docs/index.html b/docs/index.html index a14acc8f7..1abfa80f7 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1225,10 +1225,12 @@ console.log<
UUIDGeneratorNode(); // '79c7c136-60ee-40a2-beb2-856f1feabefc'
 

Object

bindAll

Use Array.forEach() to return a function that uses Function.apply() to apply the given context (obj) to fn for each function specified.

const bindAll = (obj, ...fns) =>
   fns.forEach(
-    fn =>
-      (obj[fn] = function() {
-        return fn.apply(obj);
+    fn => (
+      (f = obj[fn]),
+      (obj[fn] = function() {
+        return f.apply(obj);
       })
+    )
   );
 
var view = {
   label: 'docs',
diff --git a/snippets/bindAll.md b/snippets/bindAll.md
index 5a38d2439..da869957f 100644
--- a/snippets/bindAll.md
+++ b/snippets/bindAll.md
@@ -5,10 +5,12 @@ Use `Array.forEach()` to return a `function` that uses `Function.apply()` to app
 ```js
 const bindAll = (obj, ...fns) =>
   fns.forEach(
-    fn =>
-      (f = obj[fn], obj[fn] = function() {
+    fn => (
+      (f = obj[fn]),
+      (obj[fn] = function() {
         return f.apply(obj);
       })
+    )
   );
 ```