Advertisement
Guest User

Untitled

a guest
Jul 30th, 2015
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. var extend = function(){
  2.  
  3. function isFunction(fn){ return typeof(fn) === "function" && fn.constructor === Function }
  4. function isArray(ar){ return ar instanceof Array }
  5. function isPlainObject(obj){ return typeof o == 'object' && o.constructor == Object }
  6.  
  7. var options, name, src, copy, copyIsArray, clone, target = arguments[0] || {}, i = 1, length = arguments.length, deep = false;
  8. if(typeof target === "boolean"){
  9. deep = target;
  10. target = arguments[i] || {};
  11. i++;
  12. }
  13. if(typeof target !== "object" && !isFunction(target)) target = {};
  14. if(i === length){
  15. target = this;
  16. i--;
  17. }
  18. for(; i < length; i++){
  19. if((options = arguments[i]) != null){
  20. for(name in options){
  21. src = target[name];
  22. copy = options[name];
  23. if(target === copy) continue;
  24.  
  25. if(deep && copy &&(isPlainObject(copy) ||(copyIsArray = isArray(copy)))){
  26. if(!copyIsArray){
  27. copyIsArray = false;
  28. clone = src && isArray(src) ? src : [];
  29. }
  30. else clone = src && isPlainObject(src) ? src : {};
  31.  
  32. target[name] = extend(deep, clone, copy);
  33. }
  34. else if(copy !== undefined) target[name] = copy;
  35. }
  36. }
  37. }
  38.  
  39. return target;
  40. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement