invoke.js 445 B

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