_createAssigner.js 601 B

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