jQuery常用的全局方法源碼

下面常用方法的詳細使用請查看:http://www.cnblogs.com/moqiutao/p/4775725.html

1.$.noConflict()方法

語法:jQuery.noConflict(removeAll)

removeAll:布爾值。指示是否允許徹底將 jQuery 變量還原。

源碼:

var// Map over jQuery in case of overwrite_jQuery = window.jQuery,// Map over the $ in case of overwrite_$ = window.$;jQuery.noConflict = function( deep ) {if ( window.$ === jQuery ) {window.$ = _$;}if ( deep && window.jQuery === jQuery ) {window.jQuery = _jQuery;}return jQuery;
};

?2.$.proxy()方法

// A global GUID counter for objectsguid: 1,// Bind a function to a context, optionally partially applying any// arguments.proxy: function( fn, context ) {var tmp, args, proxy;if ( typeof context === "string" ) {tmp = fn[ context ];context = fn;fn = tmp;}// Quick check to determine if target is callable, in the spec// this throws a TypeError, but we will just return undefined.if ( !jQuery.isFunction( fn ) ) {return undefined;}// Simulated bindargs = slice.call( arguments, 2 );proxy = function() {return fn.apply( context || this, args.concat( slice.call( arguments ) ) );};// Set the guid of unique handler to the same of original handler, so it can be removedproxy.guid = fn.guid = fn.guid || jQuery.guid++;return proxy;}

?3.jQuery.extend = jQuery.fn.extend

// 合并兩個或更多對象的屬性到第一個對象中,jQuery后續的大部分功能都通過該函數擴展// 通過jQuery.fn.extend擴展的函數,大部分都會調用通過jQuery.extend擴展的同名函數// 如果傳入兩個或多個對象,所有對象的屬性會被添加到第一個對象target// 如果只傳入一個對象,則將對象的屬性添加到jQuery對象中。// 用這種方式,我們可以為jQuery命名空間增加新的方法。可以用于編寫jQuery插件。// 如果不想改變傳入的對象,可以傳入一個空對象:$.extend({}, object1, object2);// 默認合并操作是不迭代的,即便target的某個屬性是對象或屬性,也會被完全覆蓋而不是合并// 第一個參數是true,則會迭代合并// 從object原型繼承的屬性會被拷貝// undefined值不會被拷貝// 因為性能原因,JavaScript自帶類型的屬性不會合并// jQuery.extend( target, [ object1 ], [ objectN ] )// jQuery.extend( [ deep ], target, object1, [ objectN ] )

jQuery.extend = jQuery.fn.extend = function() {var options, name, src, copy, copyIsArray, clone,target = arguments[0] || {},i = 1,length = arguments.length,deep = false;// Handle a deep copy situation// 如果第一個參數是boolean型,可能是深度拷貝if ( typeof target === "boolean" ) {deep = target;target = arguments[1] || {};// skip the boolean and the target// 跳過boolean和target,從第3個開始
i = 2;}// Handle case when target is a string or something (possible in deep copy)// target不是對象也不是函數,則強制設置為空對象if ( typeof target !== "object" && !jQuery.isFunction(target) ) {target = {};}// extend jQuery itself if only one argument is passed// 如果只傳入一個參數,則認為是對jQuery擴展if ( length === i ) {target = this;--i;}for ( ; i < length; i++ ) {// Only deal with non-null/undefined values// 只處理非空參數if ( (options = arguments[ i ]) != null ) {// Extend the base objectfor ( name in options ) {src = target[ name ];copy = options[ name ];// Prevent never-ending loop// 避免循環引用if ( target === copy ) {continue;}// Recurse if we're merging plain objects or arrays// 深度拷貝且值是純對象或數組,則遞歸if ( deep && copy && ( jQuery.isPlainObject(copy) || (copyIsArray = jQuery.isArray(copy)) ) ) {// 如果copy是數組if ( copyIsArray ) {copyIsArray = false;// clone為src的修正值
clone = src && jQuery.isArray(src) ? src : [];// 如果copy的是對象
} else {// clone為src的修正值
clone = src && jQuery.isPlainObject(src) ? src : {};}// Never move original objects, clone them// 遞歸調用jQuery.extend
target[ name ] = jQuery.extend( deep, clone, copy );// Don't bring in undefined values// 不能拷貝空值
} else if ( copy !== undefined ) {target[ name ] = copy;}}}}// Return the modified object// 返回更改后的對象return target;};

?

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/541733.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/541733.shtml
英文地址,請注明出處:http://en.pswp.cn/news/541733.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

isinstance_Java類class isInstance()方法及示例

isinstance類class isInstance()方法 (Class class isInstance() method) isInstance() method is available in java.lang package. isInstance()方法在java.lang包中可用。 isInstance() method is used to check whether the given object is an instance with the object d…

Linux比較大文件內容,Linux系統最大文件打開數優化,解決Too many open files報錯

這是一個Linux系統常見的故障&#xff0c;網絡上也能輕易的找到解決辦法&#xff0c;我也只是在工作中遇到了這個問題&#xff0c;所以在博客記錄下&#xff0c;以備不時之需。一、報錯截圖&#xff1a;圖為resin的報錯日志&#xff0c;很明顯提示了Too many open files&#x…

java日歷類add方法_Java日歷computeFields()方法及示例

java日歷類add方法日歷類的computeFields()方法 (Calendar Class computeFields() method) computeFields() method is available in java.util package. 在java.util包中提供了validateFields()方法 。 computeFields() method is used to convert current ms(milliseconds) t…

Varnish緩存代理簡介與配置

一、varnish原理&#xff1a;1&#xff09;Varnish簡介&#xff1a;varnish緩存是web應用加速器&#xff0c;同時也作為http反向緩存代理。你可以安裝varnish在任何http的前端&#xff0c;同時配置它緩存內容。與傳統的 squid 相比&#xff0c;varnish 具有性能更高、速度更快、…

Linux允許61440端口,釋放對某端口的占用

釋放對某端口的占用假如我們需要確定誰占用了我們的9050端口在windows命令行窗口下執行&#xff1a;1.查看所有的端口占用情況C:\>netstat -ano協議 本地地址 外部地址 狀態 PIDTCP 127.0.0.1:1434 0.0.…

as_hash ruby_Hash.merge(other_hash)方法與Ruby中的示例

as_hash rubyHash.merge(other_hash)方法 (Hash.merge(other_hash) Method) In this article, we will study about Hash.merge(other_hash) Method. The working of the method can’t be assumed because it’s quite a different name. Let us read its definition and unde…

linux 安裝nfs 客戶端,在CentOS 7上安裝NFS服務器和客戶端

NFS服務器和客戶端安裝在CentOS 7上版本1.0作者&#xff1a;Srijan Kishore 在Twitter上關注howtoing最后編輯 16 / Dec / 2014本指南介紹如何在CentOS 7.0中配置NFS服務器網絡文件系統(NFS)是一種流行的分布式文件系統協議&#xff0c;可讓用戶在其服務器上安裝遠程目錄。 該系…

安裝ORACLE 時報錯 /jre/1.4.2/lib/i386/libawt.so:

最近在linux下安裝oracle 10g時&#xff0c;碰到如下問題&#xff1a; /tmp/OraInstall2011-09-11_02-16-11PM/jre/1.4.2/lib/i386/libawt.so: libXp.so.6: cannot open shared object file: No such file or directory occurred.. 網上找了下&#xff0c;真讓人費解呀&am…

Java線程start()vs run()方法及示例

Java | 線程start()vs run()方法 (Java | Thread start() vs run() Methods) When we call the start() method, it leads to the creation of a new thread. Then, it automatically calls the run() method. If we directly call the run() method, then no new thread will …

linux安裝卸載mysql,Linux6 系列 安裝、卸載mysql

Linux6 系列 安裝、卸載mysqlLinux6 系列 安裝、卸載mysqlLinux環境下載mysql&#xff1a;https://blog.csdn.net/weixin_40816738/article/details/90111456一、安裝環境依賴&#xff1a;yum install -y cmake make gcc gcc-c libaio ncurses ncurses-devel二、安裝流程1、軟件…

Python | 如何使用pip升級所有Python軟件包?

While using Python as a programming language, its a very common scenario to use a virtual environment and PIP, a package manager for python. 當使用Python作為編程語言時&#xff0c;使用虛擬環境和PIP (Python的程序包管理器)是一種非常常見的情況。 Its a common …

linux下enum類型占幾個字節,enum大小問題

問題描述板卡有兩個CPU&#xff0c;ARMMIPS&#xff0c;同時運行三個系統REE(linux) TEE(SierraTEE) SEE(TDS)。TEE跟SEE通過RPC進行通信&#xff0c;有enum成員的結構體信息傳遞會出錯&#xff0c;如下結構體&#xff1a;struct sTag {enum A;enum B;int C;enum D;};問題分析…

ASP.NET導出word實例

ASP.NET導出word實例 最近遇到一個題目就是如何在asp.net中將數據導出到word中&#xff0c;由于數據是動態的&#xff0c;所以需要在后臺拼出想要的的格式&#xff0c;翻遍了網頁找出了一個比較滿意的代碼&#xff0c;感謝那位高手。代碼如下&#xff1a; public void Download…

Java LocalDate類| toString()方法與示例

LocalDate類toString()方法 (LocalDate Class toString() method) toString() method is available in java.time package. toString()方法在java.time包中可用。 toString() method is used to represent this LocalDate as a String by using the standards ISO-8601 format.…

linux14.04 Apache,Ubuntu 14.04編譯安裝Apache

Ubuntu下編譯安裝apache需要預先編譯安裝多個依賴件&#xff0c;包括&#xff1a;apr, apr-util,pcre,zlib-devel&#xff0c;等&#xff0c;相當麻煩&#xff0c;記錄于此備查.由于Ubuntu系統默認安裝時沒有安裝C&#xff0c;所以也需要先安裝c編譯需要相關的組件。[注]apt-ca…

Android Jenkins自動化構建之路

install Jenkins 添加Jenkins的源&#xff08;repository&#xff09;: sudo wget -O /etc/yum.repos.d/jenkins.repo http://jenkins-ci.org/redhat/jenkins.repo sudo rpm --import http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key復制代碼yum install Jenkins復制代碼…

java 根據類名示例化類_Java即時類| plusMillis()方法與示例

java 根據類名示例化類即時類plusMillis()方法 (Instant Class plusMillis() method) plusMillis() method is available in java.time package. plusMillis()方法在java.time包中可用。 plusMillis() method is used to add the given duration in milliseconds to this Insta…

linux dd入門,Linux基礎知識:Linux中DD命令詳解

1.dd命令簡介功能&#xff1a;把指定的輸入文件拷貝到指定的輸出文件中&#xff0c;并且在拷貝過程中可以進行格式轉換。可以用該命令實現DOS下的diskcopy命令的作用。先用dd命令把軟盤上的數據寫成硬盤的一個寄存文件&#xff0c;再把這個寄存文件寫入第二張軟盤上&#xff0c…

CSS 字體(font)實例

1、設置文本字體 font-family:"Times New Roman",Georgia,Serif font-family:Arial,Verdana,Sans-serif 2、設置字體尺寸 font-size: 100% 3、設置字體風格 font-style:normal font-style:italic font-style:oblique 4、設置字體的異體 font-variant:normal text-var…

Java Duration類| 帶示例的compareTo()方法

持續時間類compareTo()方法 (Duration Class compareTo() method) compareTo() method is available in java.time package. compareTo()方法在java.time包中可用。 compareTo() method is used to compare this Duration object to the given object. compareTo()方法用于將此…