cd50a35f98bbdfefb717352826dbc6c7971c88e108787d9fd9a9b009d0cbf64f78e720fb0e1e837a55420d482b8e4f380e0ebfb9d32466e107969059506af2 520 B

1234567891011121314151617181920
  1. // optional / simple context binding
  2. var aFunction = require('./_a-function');
  3. module.exports = function (fn, that, length) {
  4. aFunction(fn);
  5. if (that === undefined) return fn;
  6. switch (length) {
  7. case 1: return function (a) {
  8. return fn.call(that, a);
  9. };
  10. case 2: return function (a, b) {
  11. return fn.call(that, a, b);
  12. };
  13. case 3: return function (a, b, c) {
  14. return fn.call(that, a, b, c);
  15. };
  16. }
  17. return function (/* ...args */) {
  18. return fn.apply(that, arguments);
  19. };
  20. };