methods.js 933 B

1234567891011121314151617181920212223242526272829303132
  1. "use strict";
  2. var forEach = require("es5-ext/object/for-each")
  3. , normalizeOpts = require("es5-ext/object/normalize-options")
  4. , callable = require("es5-ext/object/valid-callable")
  5. , lazy = require("d/lazy")
  6. , resolveLength = require("./resolve-length")
  7. , extensions = require("./registered-extensions");
  8. module.exports = function (memoize) {
  9. return function (props) {
  10. forEach(props, function (desc) {
  11. var fn = callable(desc.value), length;
  12. desc.value = function (options) {
  13. if (options.getNormalizer) {
  14. options = normalizeOpts(options);
  15. if (length === undefined) {
  16. length = resolveLength(
  17. options.length,
  18. fn.length,
  19. options.async && extensions.async
  20. );
  21. }
  22. options.normalizer = options.getNormalizer(length);
  23. delete options.getNormalizer;
  24. }
  25. return memoize(fn.bind(this), options);
  26. };
  27. });
  28. return lazy(props);
  29. };
  30. };