jQuery API jQuery API 中英文对照版
$.extend(target, prop1, propN)
$.extend(target,prop1,propN)

用一个或多个其他对象来扩展一个对象,返回这个被扩展的对象。这是简化继承的主要工具。

返回值:Object

参数:

  • target (Object): 要扩展的对象
  • prop1 (Object): 要与第一个对象合并的对象
  • propN (Object): (可选) 更多要与第一个对象合并的对象
 
示例:

合并settings和options, 修改并返回settings

var settings = { validate: false, limit: 5, name: "foo"   };
var options = { validate: true, name: "bar" };
jQuery.extend(settings,   options); 

结果:

settings == { validate: true, limit: 5, name: "bar" }

示例:

合并defaults和options, 但不修改defaults,返回合并后的对象

ar defaults = { validate: false, limit: 5, name: "foo"   };
var options = { validate: true, name: "bar" };
var settings =   jQuery.extend({}, defaults, options); 

结果:

settings == { validate: true, limit: 5, name: "bar" }

 
$.extend( target, prop1, propN )

Extend one object with one or more others, returning the original, modified, object. This is a great utility for simple inheritance.

Return value: Object
Parameters:

  • target (Object): The object to extend
  • prop1 (Object): The object that will be merged into the first.
  • propN (Object): (optional) More objects to merge into the first
 

Example:

Merge settings and options, modifying settings

var settings = { validate: false, limit: 5, name: "foo" };   
var options = { validate: true, name: "bar" };   
jQuery.extend(settings, options);  
Result:
 settings == { validate: true, limit: 5, name: "bar" }  

Example:

Merge defaults and options, without modifying the defaults

 var empty = {};
 var defaults = { validate: false, limit: 5, name: "foo" };
 var options = { validate: true, name: "bar" };
 var settings = jQuery.extend(empty, defaults, options);  
Result:
 settings == { validate: true, limit: 5, name: "bar" }
 empty == { validate: true, limit: 5, name: "bar" }  


相关链接
WEB开发网 | PHP教程 | Mysql教程 | Apache教程 | 最新文章 | PHP面试题| 网站地图 | Google地图 | Baidu地图 | 在线WEB论坛

WEB技术QQ交流群:245735*** 站长Q号:245735***
版权所有者:WEB开发网 地址:云南省文山州砚山县盘龙乡 滇ICP备12002707号-10
特别声明:本站内容仅供参考,不作为设计及确切依据!想了解更多,可立即进入Bbs提问