jquery的extend方法
2016-04-26 09:39
501 查看
DifferencebetweenjQuery.extendandjQuery.fn.extend?
一遇到extend或写插件的时候我总是翻几个这样的文章看,终于在stackoverflow上找到了一个很棒的答案。
Actually,thereisnoneapartfromtheirbasereference.InthejQuerysource,youcanread:
Sohowdoesitwork?Thedocumentationreads:
Mergesthecontentsoftwoormoreobjectstogetherintothefirstobject.
一遇到extend或写插件的时候我总是翻几个这样的文章看,终于在stackoverflow上找到了一个很棒的答案。
Actually,thereisnoneapartfromtheirbasereference.Inthe
jQuery.extend=jQuery.fn.extend=function(){…};
Sohowdoesitwork?The
Mergesthecontentsoftwoormoreobjectstogetherintothefirstobject.
It'sjustafor-in-loopthatcopiesproperties,pimpedupwithaflagtorecursenestedobjects.Andanotherfeature:
Ifonlyoneargumentissuppliedto
$.extend(),thismeansthetargetargumentwasomitted
//thenthefollowingwillhappen: target=this;
Soifthefunctioniscalledon
jQueryitself(withoutexplicittarget),itwillextendthejQuerynamespace.
Andifthefunctioniscalledon
jQuery.fn(withoutexplicittarget),itwillextendthejQueryprototypeobjectwhereallthe(plugin)methodsarelocated.[/code]
相关文章推荐
- Jquery - Javascript 基本问题汇总
- jQuery ajax序列化函数
- jquery 扩展编写及时更新
- jQuery Mobile页面返回不需要重新get
- jQuery 中的 DOM 操作
- Jquery attr与prop区别
- jQuery ajax中的get请求方法汇总
- jQuery 中的 DOM 操作
- jQuery Mobile页面返回不需要重新get
- JQuery插件Marquee.js实现无缝滚动效果
- jQuery siblings()用法实例详解
- 无需 Flash 使用 jQuery 复制文字到剪贴板
- JQuery给select添加/删除节点的实现代码
- jQuery javascript获得网页的高度与宽度的实现代码
- 基于Jquery插件实现跨域异步上传文件功能
- jQuery 字符串替换(默认只替换第一个,本方法替换全部)
- jQuery html5Validate基于HTML5表单验证插件
- JQuery对CheckBox的一些相关操作
- jQuery Mobile
- 紧接上篇,jQuery调用jsonp,并且在页面上展示