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); 

你可能感兴趣的:(jquery api)