UUIDGeneratorNode(); // '79c7c136-60ee-40a2-beb2-856f1feabefc'
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); }) + ) ); ```