_createAssigner.js 656 B

123456789101112131415161718192021222324
  1. define(function () {
  2. // An internal function for creating assigner functions.
  3. function createAssigner(keysFunc, defaults) {
  4. return function(obj) {
  5. var length = arguments.length;
  6. if (defaults) obj = Object(obj);
  7. if (length < 2 || obj == null) return obj;
  8. for (var index = 1; index < length; index++) {
  9. var source = arguments[index],
  10. keys = keysFunc(source),
  11. l = keys.length;
  12. for (var i = 0; i < l; i++) {
  13. var key = keys[i];
  14. if (!defaults || obj[key] === void 0) obj[key] = source[key];
  15. }
  16. }
  17. return obj;
  18. };
  19. }
  20. return createAssigner;
  21. });