User Tools

Site Tools


ui:jquery-analysis

Table of Contents

Introduce

Everyone can learn a lot from jquery framework, so let's record my learning.

base on http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js

Morgan.L 2012/05/02 08:52

isArray & Others

isFunction: function( obj ) {
	return toString.call(obj) === "[object Function]";
},
 
isArray: function( obj ) {
	return toString.call(obj) === "[object Array]";
},
 
isPlainObject: function( obj ) {
	// Must be an Object.
	// Because of IE, we also have to check the presence of the constructor property.
	// Make sure that DOM nodes and window objects don't pass through, as well
	if ( !obj || toString.call(obj) !== "[object Object]" || obj.nodeType || obj.setInterval ) {
		return false;
	}
 
	// Not own constructor property must be Object
	if ( obj.constructor
		&& !hasOwnProperty.call(obj, "constructor")
		&& !hasOwnProperty.call(obj.constructor.prototype, "isPrototypeOf") ) {
		return false;
	}
 
	// Own properties are enumerated firstly, so to speed up,
	// if last one is own, then all properties are own.
 
	var key;
	for ( key in obj ) {}
 
	return key === undefined || hasOwnProperty.call( obj, key );
},
 
isEmptyObject: function( obj ) {
	for ( var name in obj ) {
		return false;
	}
	return true;
},

This is a good way to judge where object is array or not.

Morgan.L 2012/05/02 08:52

More

ui/jquery-analysis.txt · Last modified: 2018/07/24 08:13 by 127.0.0.1

Except where otherwise noted, content on this wiki is licensed under the following license: 沪ICP备12046235号-2
Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki