Created
July 23, 2013 03:37
-
-
Save markyun/6059668 to your computer and use it in GitHub Desktop.
jQuery的代码结构
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(){ | |
//jQuery变量定义 | |
var jQuery = function(){...}; | |
//jQuery原型定义(包含核心方法) | |
jQuery.fn = jQuery.prototype = {...}; | |
//看上去很奇怪吧? 非常巧妙的设计,后面详细介绍 | |
jQuery.fn.init.prototype = jQuery.fn; | |
//提供jQuery静态方法与对象方法的扩展函数 | |
jQuery.extend = jQuery.fn.extend = function(){...}; | |
//后面依次有多个对jQuery静态方法的扩展 | |
jQuery.extend({...}); | |
//后面依次有多个对jQuery对象方法的扩展 | |
jQuery.fn.extend({...}); | |
jQuery.support = (function() {...})(); | |
//提供统一时间管理,jQuery内部使用,并不对外开放 | |
jQuery.event = {...}; | |
//Event类似于Java的POJO类.传递事件的对象 | |
jQuery.Event = function( src, props ) {...}; | |
//Sizzle选择器,一个框架,可独立使用。 | |
(function(){ | |
... | |
jQuery.find = Sizzle; | |
... | |
})(); | |
... | |
//将定义的jQuery定义为全局变量 | |
window.jQuery = window.$ = jQuery; | |
... | |
})(); | |
var jQuery = function( selector, context ) { | |
// The jQuery object is actually just the init constructor 'enhanced' | |
return new jQuery.fn.init( selector, context, rootjQuery ); | |
} | |
和 | |
jQuery.fn.init.prototype = jQuery.fn; | |
var jQuery = function( selector, context ) { | |
return new A( selector, context); | |
} | |
var A = function(){ | |
if(this.init) { | |
this.init(); | |
} | |
}; | |
A.prototype = jQuery.prototype; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment