Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

bindAll.js 639B

12345678910111213141516171819
  1. var _flatten = require('./_flatten.js');
  2. var restArguments = require('./restArguments.js');
  3. var bind = require('./bind.js');
  4. // Bind a number of an object's methods to that object. Remaining arguments
  5. // are the method names to be bound. Useful for ensuring that all callbacks
  6. // defined on an object belong to it.
  7. var bindAll = restArguments(function(obj, keys) {
  8. keys = _flatten(keys, false, false);
  9. var index = keys.length;
  10. if (index < 1) throw new Error('bindAll must be passed function names');
  11. while (index--) {
  12. var key = keys[index];
  13. obj[key] = bind(obj[key], obj);
  14. }
  15. return obj;
  16. });
  17. module.exports = bindAll;