API Docs for: 0.0.8
Show:

File: client/lib/function.js

  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. /**
  5. * Simple function helpers.
  6. *
  7. * @class Function
  8. * @static
  9. */
  10. define(function () {
  11. 'use strict';
  12. function partial(method/*, ...*/) {
  13. var args = [].slice.call(arguments, 1);
  14. return function () {
  15. return method.apply(this, args.concat([].slice.call(arguments, 0)));
  16. };
  17. }
  18. return {
  19. /**
  20. * Partially apply a function by filling in any number of its arguments,
  21. * without changing its dynamic this value. A close cousin of
  22. * [Function.prototype.bind](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function/bind).
  23. *
  24. * @example
  25. * function add(a, b) {
  26. * return a + b;
  27. * }
  28. *
  29. * var add10To = partial(add, 10);
  30. * var result = add10To(9);
  31. * // result is 19
  32. *
  33. * @method partial
  34. * @param method {Function}
  35. * Method to call with the arguments on final evaluation.
  36. * @returns {Function}
  37. */
  38. partial: partial
  39. };
  40. });