jqueryでのisArrayメソッド解析


<!DOCTYPE html>
<html>
<head>
<title>jq  isArray    </title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>

<body>
<div class="warp">

</div>
<script type="text/javascript">
//    jquery 1.9       

var class2type = {},core_toString = class2type.toString;
// firefox chrome IE9 IE10     Array.isArray
//     Array.isArray([])      true
//   IE7         
var isArray = Array.isArray || function( obj ) {
		return type(obj) === "array";
};
/*
          948 
jQuery.each("Boolean Number String Function Array Date RegExp Object Error".split(" "), function(i, name) {
	class2type[ "[object " + name + "]" ] = name.toLowerCase();
});
          ,       type([])     object
      JS     
*/
var arr = "Boolean Number String Function Array Date RegExp Object Error".split(" ");
for(var i in arr){
	class2type[ "[object " + arr[i] + "]" ] = arr[i].toLowerCase();
};


var  type = function( obj ) {
	if ( obj == null ) {
		return String( obj );
	}
	return typeof obj === "object" || typeof obj === "function" ?
		class2type[ core_toString.call(obj) ] || "object" :
		typeof obj;
	//    return (typeof obj === "object" || typeof obj === "function")?(class2type[ core_toString.call(obj) ] || "object"): typeof obj;

};
//      

//                         return Object.prototype.toString.call(obj) === '[object Array]';
//     http://sofish.de/1591
</script>
</body>
</html>