您的位置:首页 > Web前端 > JQuery

jquery的extend方法

2016-04-26 09:39 501 查看
DifferencebetweenjQuery.extendandjQuery.fn.extend?

一遇到extend或写插件的时候我总是翻几个这样的文章看,终于在stackoverflow上找到了一个很棒的答案。

Actually,thereisnoneapartfromtheirbasereference.InthejQuerysource,youcanread:

jQuery.extend=jQuery.fn.extend=function(){…};

Sohowdoesitwork?Thedocumentationreads:


Mergesthecontentsoftwoormoreobjectstogetherintothefirstobject.


It'sjustafor-in-loopthatcopiesproperties,pimpedupwithaflagtorecursenestedobjects.Andanotherfeature:


Ifonlyoneargumentissuppliedto
$.extend()
,thismeansthetargetargumentwasomitted


//thenthefollowingwillhappen:
target=this;


Soifthefunctioniscalledon
jQuery
itself(withoutexplicittarget),itwillextendthejQuerynamespace.
Andifthefunctioniscalledon
jQuery.fn
(withoutexplicittarget),itwillextendthejQueryprototypeobjectwhereallthe(plugin)methodsarelocated.[/code]

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐
章节导航