mixIn.js 785 B

12345678910111213141516171819202122232425262728
  1. var forOwn = require('./forOwn');
  2. /**
  3. * Combine properties from all the objects into first one.
  4. * - This method affects target object in place, if you want to create a new Object pass an empty object as first param.
  5. * @param {object} target Target Object
  6. * @param {...object} objects Objects to be combined (0...n objects).
  7. * @return {object} Target Object.
  8. */
  9. function mixIn(target, objects){
  10. var i = 0,
  11. n = arguments.length,
  12. obj;
  13. while(++i < n){
  14. obj = arguments[i];
  15. if (obj != null) {
  16. forOwn(obj, copyProp, target);
  17. }
  18. }
  19. return target;
  20. }
  21. function copyProp(val, key){
  22. this[key] = val;
  23. }
  24. module.exports = mixIn;