jQuery extend 的简单实例
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
if ( typeof target === "boolean" ) {
deep = target;
target = arguments[1] || {};
// skip the boolean and the target
i = 2;
}// Handle case when target is a string or something (possible in deep copy)
if ( typeof target !== "object" && !jQuery.isFunction(target) ) {
target = {};
}// extend jQuery itself if only one argument is passed
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 object
for ( 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)) ) ) {
if ( copyIsArray ) {
copyIsArray = false;
clone = src && jQuery.isArray(src) ? src : [];} else {
clone = src && jQuery.isPlainObject(src) ? src : {};
}// Never move original objects, clone them
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;
};
您可能感兴趣的文章:
- jQuery extend 的简单实例
- jQuery extend()详解及简单实例
- [LinkerScript.3] 简单的链接器脚本实例 - Simple Linker Script Example
- 本文实现了一个基于servlet技术的简单的csv文件导出的程序实例。
- Spring + Springmvc + myBatis 简单实例
- windows下使用RedisCluster集群简单实例
- 简单实例讲解linux的module模块编译步骤
- JSP简单练习-数组应用实例
- mybatis复杂应用的简单实例
- 一个最简单的SOAP客户端与服务端测试实例(主要是该例子一个类中写了多个方法)
- Java中三种简单注解介绍和代码实例
- IOS 一个简单地相对布局实例
- PHP编程 SSO详细介绍及简单实例
- 一个简单分页的实例
- netty简单实例
- Json转换利器Gson之实例一-简单对象转化和带泛型的List转化
- shell编程实例三实现简单运算符
- 第十四回 基础才是重中之重~委托实例的几种定义方式(规规矩矩method,逻辑简单delegate,层次清晰lambda)
- Struts(三)——一个简单Struts实例 .
- 实例讲解C++中CopyFileEx函数的简单用法