jQuery.extend
生活随笔
收集整理的這篇文章主要介紹了
jQuery.extend
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
extend
var?target?=?arguments[0]?||?{},?//?第一個(gè)參數(shù)是目標(biāo)
i?=?1,?length?=?arguments.length,?deep?=?false,?options;
if?(target.constructor?==?Boolean)?{//?第一個(gè)參數(shù)是bool型的
?deep?=?target;//?深度copy
?target?=?arguments[1]?||?{};//?target指向第二個(gè)參數(shù)
?i?=?2;
}
//?target?是string?型的或?
if?(typeof?target?!=?"object"?&&?typeof?target?!=?"function")
?target?=?{};
if?(length?==?i)?{//?只有一個(gè)參數(shù)?或deep?copy?時(shí),兩個(gè)參數(shù)
?target?=?this;//?目標(biāo)為this
?--i;
}
for?(;i?<?length;?i++)
?if?((options?=?arguments[i])?!=?null)
?for?(var?name?in?options)?{
var?src?=?target[name],?copy?=?options[name];
if?(target?===?copy)//?防止死循環(huán)
continue;
//?深度copy處理,最深為元素
if?(deep?&&?copy?&&?typeof?copy?==?"object"?&&?!copy.nodeType)
target[name]?=?jQuery.extend(deep,?src
?||?(copy.length?!=?null???[]?:?{}),?copy);
else?if?(copy?!==?undefined)//?直接copy
target[name]?=?copy;
?}
return?target;
};
有人批評(píng)(好像是fins)prototype,說它是一個(gè)extend支撐半邊天。對(duì)于Jquery而言,也是一個(gè)extend支持了一邊天。Jquery提供了extend對(duì)jquery進(jìn)行擴(kuò)展。jQuery.fn.extend是對(duì)jquery對(duì)象進(jìn)行擴(kuò)展。jQuery.extend是對(duì)jquery的靜態(tài)方法進(jìn)行擴(kuò)展。它們是同一個(gè)方法。
?
jQuery.extend?=?jQuery.fn.extend?=?function()?{var?target?=?arguments[0]?||?{},?//?第一個(gè)參數(shù)是目標(biāo)
i?=?1,?length?=?arguments.length,?deep?=?false,?options;
if?(target.constructor?==?Boolean)?{//?第一個(gè)參數(shù)是bool型的
?deep?=?target;//?深度copy
?target?=?arguments[1]?||?{};//?target指向第二個(gè)參數(shù)
?i?=?2;
}
//?target?是string?型的或?
if?(typeof?target?!=?"object"?&&?typeof?target?!=?"function")
?target?=?{};
if?(length?==?i)?{//?只有一個(gè)參數(shù)?或deep?copy?時(shí),兩個(gè)參數(shù)
?target?=?this;//?目標(biāo)為this
?--i;
}
for?(;i?<?length;?i++)
?if?((options?=?arguments[i])?!=?null)
?for?(var?name?in?options)?{
var?src?=?target[name],?copy?=?options[name];
if?(target?===?copy)//?防止死循環(huán)
continue;
//?深度copy處理,最深為元素
if?(deep?&&?copy?&&?typeof?copy?==?"object"?&&?!copy.nodeType)
target[name]?=?jQuery.extend(deep,?src
?||?(copy.length?!=?null???[]?:?{}),?copy);
else?if?(copy?!==?undefined)//?直接copy
target[name]?=?copy;
?}
return?target;
};
轉(zhuǎn)載于:https://www.cnblogs.com/orez88/articles/1394962.html
總結(jié)
以上是生活随笔為你收集整理的jQuery.extend的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 利用反射,实现动态调用winform窗体
- 下一篇: 基于DOM的Web信息提取方法