1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
| const _String = Object.prototype.toString;
function getType(item) { return _String.call(item).slice(8, -1); }
function isType(item, type) { return item && type && item === type; }
function isPlianObejct(obj) { return ( Object.getPrototypeOf(obj) === Object.prototype && isWindow(obj) && isType(obj, 'Object') ); }
function isWindow(obj) { return obj != null && obj === obj.window; }
function extend() { let target = arguments[0] || {}, i = 1, lens = arguments.length, deep = false;
let options, name, src, copy, copyIsArr, clone;
if (typeof target === 'boolean') { deep = target; target = arguments[1]; i++; } if (typeof target !== 'object' && isType(target, 'Function')) { target = {}; }
if (i === lens) { target = this; i--; }
for (; i < lens; i++) { if ((options = arguments[i]) != null) { for (name in options) { src = target[name]; copy = options[name];
if (src === copy) { continue; }
if ( deep && copy && isPlianObejct(copy || (copyIsArr = isType(copy, 'Array'))) ) { if (copyIsArr) { clone = src && isType(src, 'Array') ? src : []; } else { clone = src && isPlianObejct(obj) ? src : {}; } target[name] = extend(deep, clone, copy); } else if (copy !== undefined) { target[name] = copy; } } } } }
|