bindAll.js 521 B

12345678910111213141516171819
  1. var functions = require('./functions');
  2. var bind = require('../function/bind');
  3. var forEach = require('../array/forEach');
  4. var slice = require('../array/slice');
  5. /**
  6. * Binds methods of the object to be run in it's own context.
  7. */
  8. function bindAll(obj, rest_methodNames){
  9. var keys = arguments.length > 1?
  10. slice(arguments, 1) : functions(obj);
  11. forEach(keys, function(key){
  12. obj[key] = bind(obj[key], obj);
  13. });
  14. }
  15. module.exports = bindAll;