关于JQuery源码解析
来源:互联网 发布:查重软件有哪些 编辑:程序博客网 时间:2024/05/19 14:19
源码分析-----整体架构
1.首先关于jQuery的闭包结构
(function(window,undefined){ //jquery代码 jquery=function(selector,context){ return new jQuery.fn.init(selector,context,rootjQuery); }; jQuery.fn=jQuery.prototype={ init:function(selector,context,rootjQuery){ //.... }; } jquery.fn.init.prototype=jQuery.fn; window.jQuery=window.$=jQuery; })(window);
为了不造成全局污染和变量冲突,整个实现都包含在一个立即执行的闭包环境里,只在后面暴露了$和jQuery两个变量.
2.jquery实例化对象
在使用$(””),时,其内部调用的是return new jQuery.fn.init(selector,context),其次jquery.fn.init的prototype属性设置为jQuery.fn;所以new jquery.fn.init()生成的对象就能访问到jQuery.fn上的所有原型方法。
3.关于jQuery方法的扩展
extend是jquery中的很重要的一个方法。jquery内部用来扩展静态方法和实例方法。jQuery.extend 是扩展jQuery本身,为类添加新的静态方法。jQuery.fn.extend是给jQuery对象添加实例方法 ,但同时jQuery.fn=jQuery.prototype,所以实例化的对象都能使用。jQuery.extend扩展的静态方法可以通过
1)在 jQuery.extend() 中,this 的指向是 jQuery 对象(或者说是 jQuery 类),所以这里扩展在 jQuery 上;且上下文指向是jQuery构造器
2)在 jQuery.fn.extend() 中,this 的指向是 fn 对象,前面有提到 jQuery.fn = jQuery.prototype ,也就是这里增加的是原型方法,也就是对象方法。
0 0
- 关于JQuery源码解析
- JQuery validation源码解析
- jquery源码解析
- jquery源码解析
- jquery源码解析资料
- jQuery.extend()源码解析
- jQuery 源码解析(一)
- jquery源码解析1
- 浅谈jquery源码解析
- jQuery源码解析data
- jquery.parser源码解析
- jquery源码解析
- jQuery.lazyload源码解析
- 01Jquery源码解析
- 04jQuery源码解析
- 05jQuery源码解析
- 08jQuery源码解析
- jquery源码解析
- Paint、Canvas、Matrix使用讲解
- android 从setContentView到window显示机制
- qt 之 生成pdf
- iOS 指定设置控件圆角
- tornado和ajax交互
- 关于JQuery源码解析
- TextView中文字的跑马灯效果实现,以及focusable,focusableInTouchMode属性介绍
- RSA密码系统
- qt 之 加密算法
- mysql 5.7 增加用户并授权
- wemall商城 7.0 开源系统发布,支持公众号和小程序开发
- selenium--unittest字符串/整型问题Can't convert 'int' object to str implicitly提示解决方法
- 简单拍照
- python 爬虫之路教程