标签:nbsp type bool foreach isp span end cal div
通过源对象扩展目标对象的属性,源对象属性将覆盖目标对象属性。
默认情况下为,复制为浅复制。如果第一个参数为true表示深度复制
1 $.extend = function (target) { 2 var deep, args = slice.call(arguments, 1) 3 if (typeof target == ‘boolean‘) { 4 deep = target 5 target = args.shift() 6 } 7 args.forEach(function (arg) { 8 extend(target, arg, deep) 9 }) 10 return target 11 } 12 13 function extend(target, source, deep) { 14 for (key in source) 15 if (deep && (isPlainObject(source[key]) || isArray(source[key]))) { 16 if (isPlainObject(source[key]) && !isPlainObject(target[key])) 17 target[key] = {} 18 if (isArray(source[key]) && !isArray(target[key])) 19 target[key] = [] 20 extend(target[key], source[key], deep) 21 } 22 else if (source[key] !== undefined) target[key] = source[key] 23 }
标签:nbsp type bool foreach isp span end cal div
原文地址:http://www.cnblogs.com/sunnie-cc/p/6797977.html