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.mzph.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()方法用于将此…