jquery api

 

jQuery.isPlainObject()

It's pretty hard to detect a plain object in javascript, mostly due to the "bad parts" of javascript.

the most obvious solution would be
if (typeof(myvar) === "object")

BUT:
typeof(null) also returns "object"

so jQuery.isPlainObject() can be used to reliably check whether a variable is really an object and not null.

A use case would be to check the data type of a variable stored with $.data().

Furthermore many Javascript programmers initialise their variables with null and assign them values later depending on certain events or conditions. This is the source of the common 'var xy is null or not an object' error: The programmer assumed that xy is currently an object, but it still is null because no condition was met.

An example of this is a test against document.location using $.isPlainObject() as follows:

console.log($.isPlainObject(document.location));

which throws an invalid pointer exception in IE8.

Example:

Check an object to see if it's a plain object.
jQuery.isPlainObject({}) // true 
jQuery.isPlainObject("test") // false

 

jQuery.isEmptyObject( object )

objectThe object that will be checked to see if it's empty.

As of jQuery 1.4 this method checks both properties on the object itself and properties inherited from prototypes (in that it doesn't use hasOwnProperty). The argument should always be a plain JavaScriptObject as other types of object (DOM elements, primitive strings/numbers, host objects) may not give consistent results across browsers. To determine if an object is a plain JavaScript object, use$.isPlainObject()

 

jQuery.extend()
jQuery.extend( [deep], target, object1 [, objectN] )

deepIf true, the merge becomes recursive (aka. deep copy).

targetThe object to extend. It will receive the new properties.

 

object1An object containing additional properties to merge in.

objectNAdditional objects containing properties to merge in.

/* merge object2 into object1 */
 $ . extend ( object1 , object2 );  
/* merge object2 into object1, recursively
*/ $.extend(true, object1, object2); 
/* merge defaults and options, without modifying defaults */
 var settings = $.extend({}, defaults, options); 
&&
10-21 522
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值