javaScript 是一门基于对象的语言,然而它的对象技术的实现与其他的语言有很大的差异。
在javaScript中,定义一个类的一般采用以下这种模式:
//定义一个构造函数
testClass(param1,param2){
this.att1=param1;
this.att2=param2;
....
}
// 在prototype对象上扩展,加上相应的方法;
testClass.prototype = {
Method1: function() {...},
Method2: function() {...},
...
}
// 定义一个实例;
var test = new testClass();
在jQuery.js中,同样也是这种模式,只不过它要复杂很多,而且它还定义了一个jQuery.extend()的静态方法来扩展类的功能,jQuery.js代码执行过程完整分析如下:
// 防止多次载入而进行jQuery对象的判断;
if ( typeof window.jQuery == "undefined" ) {
window.undefined = window.undefined;
// jQuery的构造函数;
var jQuery = function( a, c ) { ... };
// jQuery的命名空间$;
if ( typeof $ != "undefined" ) jQuery._$ = $;
var $ = jQuery;
// 给jQuery的prototype增加一些基础方法和属性;
// 其中有些方法是调用下面的扩展方法实现的;
// 注意下面的jQuery.fn = jQuery.prototype;
jQuery.fn = jQuery.prototype = {
each: function( fn, args ) { ... },
find: function( t ) { ... },
...
};
// jQuery实现继承的方法;
jQuery.extend = jQuery.fn.extend = function( obj, prop ) {...};
// 实现一些基础的函数,有大部分是上面调用;
jQuery.extend({
init: function() { ... },
each: function( obj, fn, args ) { ... },
find: function( t, context ) { ... },
...
});
// 浏览器版本的检测;
new function() {
jQuery.browser = { safari:..., opera:..., msie:..., mozilla:... };
...
};
// jQuery.macros扩展,主要用于jQuery.init(),进行jQuery的初始化;
jQuery.macros = {
filter: [ ... ],
attr: { ... },
each: { ... },
...
};
// jQuery初始化;
jQuery.init();
// 实现jQuery的重要方法ready();
jQuery.fn.extend({
ready: function( f ) { ... }
...
};
// 上面ready()方法的具体实现;
jQuery.extend({
ready: function() { ... },
...
};
// 对浏览器某些事件进行绑定和解绑定;
new function() {
...
jQuery.event.add( window, "load", jQuery.ready );
};
// 当IE浏览器关闭时,清除上面绑定的事件,防止内存泄漏;
if ( jQuery.browser.msie ) jQuery(window).unload( ... );
// 实现一些浏览器效果;
jQuery.fn.extend({
show: function( speed, callback ) { ... },
hide: function( speed, callback ) { ... },
...
};
// 上面的一些函数具体实现;
jQuery.extend( {...} );
// 以下都是Ajax的实现,这里声明原型,具体实现调用下面的函数;
jQuery.fn.extend({
loadIfModified: function(url, params, callback ) { ... },
...
};
// 针对IE浏览器创建不同的XMLHttpRequest对象;
if (jQuery.browser.msie && typeof XMLHttpRequest == "undefined") { ... };
// Ajax函数的绑定;
new function() {
var e = "ajaxStart,ajaxStop,ajaxComplete,ajaxError,ajaxSuccess".split(",");
...
};
// Ajax函数的具体实现;
jQuery.extend({
get: function( url, data, callback, type, ifModified ) { ... },
post: function( url, data, callback, type ) { ... },
ajax: function( type, url, data, ret, ifModified ) { ... },
...
}
}
分享到:
相关推荐
jquery插件jquery-ui-1.8.18.custom.min.js
jquery-uijquery-uijquery-uijquery-uijquery-uijquery-uijquery-uijquery-uijquery-uijquery-uijquery-uijquery-uijquery-uijquery-uijquery-uijquery-ui
jquery-ui-1.8.2.custom.min.js,jquery-ui-1.8.4.custom.css
这里包含jquery-ui-1.8.16.custom.min.js/jquery-ui-1.8.16.custom.css,我费了好长时间找到的,此东西可以配合jQuery UI开发指南一书使用。
jquery-ui-日期框扩展成时间框 jquery-ui时间框 基于别人的代码进行修改 jquery-ui-1.8.16.custom.css文件末尾加入以下代码 .ui-timepicker-div .ui-widget-header{ margin-bottom: 8px; } .ui-timepicker-div dl{ ...
jquery插件jquery-ui-1.8.2.custom.min.js
<script src="./public/js/jquery-ui-1.10.3.min.js"> <script src="./public/js/jquery.datepicker-zh-CN.js"></script> <link href="./public/css/jqueryui/jquery-ui-1.10.3.min.css" rel="stylesheet"> $( "#...
jquery-easyui-EDT-1.5.2-build1 jquery-easyui-EDT-1.5.2-build1
jquery-ui-1.8.16jquery-ui-1.8.16jquery-ui-1.8.16jquery-ui-1.8.16jquery-ui-1.8.16jquery-ui-1.8.16jquery-ui-1.8.16jquery-ui-1.8.16jquery-ui-1.8.16jquery-ui-1.8.16jquery-ui-1.8.16jquery-ui-1.8.16jquery-...
jquery-ui-1.8.18.custom
压缩包内包含jquery-1.6.4.js jquery-1.6.4.min.js jquery-1.6.4-vsdoc.js 。 【推荐用法】 1、将jquery-1.6.4-vsdoc.js与jquery-1.6.4.js放在同一目录,然后在vs中添加对jquery-1.6.4.js的引用即可; 2、切记:...
jquery-ui-1.7.3.custom JQUERY UI
${ctx}/plugins/jquery-ui-1.11.2/jquery-ui.css" > ${ctx}/plugins/jquery-ui-1.11.2/external/jquery/jquery.js"> ${ctx}/plugins/jquery-ui-1.11.2/jquery-ui.js"> ${ctx}/plugins/jquery-ui-1.11.2/jquery-ui-...
jquery.mobile-1.4.5 jquery.mobile-1.4.5 jquery.mobile-1.4.5
jQuery版本迁移辅助插件,如果您使用的低版本jQuery改为高版本后出现错误,可以试试这个插件。用来检测和恢复在jQuery1.9版本中已删除或已过时的API。jquery-migrate-1.2.1.js,jquery-migrate-1.2.1.min.js
jquery-migrate-1.2.1.js文件,处理jQuery和jqprint插件的版本不兼容问题
jquery-ui-1.7.3.custom 完整开发包
jquery-1.4.2-vsdoc.js jquery-1.4.4-vsdoc.js
jquery-migrate-1.2.1.min.js 在网上下载一些 js 插件使用的时候,经常出现这种情况。但是更换低版本 jquery,比如 使用 1.7 版本的 jquery 却不会报错,能正常使用。 经过一番搜索,发现是因为高版本(1.9版本以后)...
jquery-ui-1.9.2.custom.min.js