invoke.js 436 B

123456789101112131415
  1. 'use strict';
  2. var isCallable = require('../object/is-callable')
  3. , value = require('../object/valid-value')
  4. , slice = Array.prototype.slice, apply = Function.prototype.apply;
  5. module.exports = function (name/*, …args*/) {
  6. var args = slice.call(arguments, 1), isFn = isCallable(name);
  7. return function (obj) {
  8. value(obj);
  9. return apply.call(isFn ? name : obj[name], obj,
  10. args.concat(slice.call(arguments, 1)));
  11. };
  12. };