<script>
var getProto = Object.getPrototypeOf;
var class2type = {};
var toString = class2type.toString;//Object.prototype.toString
var hasOwn = class2type.hasOwnProperty;//Object.prototype.hasOwnProperty
var fnToString = hasOwn.toString;//Function.prototype.toString
var ObjectFunctionString = fnToString.call(Object);ToSring () => "function Object() {[native code]}"
// Check if it is a function
var isFunction = function isFunction(obj) {
// Support: Chrome <=57, Firefox <=52
// In some browsers, typeof returns "function" for HTML <object> elements
// (i.e., 'typeof document.createElement("object") === "function"').// Create a tag
// We don't want to classify *any* DOM node as a function.
// Support: QtWeb <=3.8.5, WebKit <=534.34, wkhtmltopdf tool <=0.12.5
// Plus for old WebKit, typeof returns "function" for HTML collections
// (e.g., `typeof document.getElementsByTagName("div") === "function"`). (gh-4756)
return typeof obj === "function" && typeofobj.nodeType ! = ="number" &&
typeofobj.item ! = ="function";
typeofobj.item ! = ="function";//obj.item is not function
};
// Check if it is a window object
var isWindow = function isWindow(obj) {
// window.window===window
returnobj ! =null && obj === obj.window;
};
// A standard method for detecting data types
/* var arr = ["Boolean", "Number", "String", "Function", "Array", "Date", "RegExp", "Object", "Error", "Symbol"]; arr.forEach(function (name) { class2type["[object " + name + "]"] = name.toLowerCase(); }); var toType = function toType(obj) { if (obj == null) return obj + ""; return typeof obj === "object" || typeof obj === "function" ? class2type[toString.call(obj)] || "object" : typeof obj; }; * /
var toType = function toType(obj) {
if (obj == null) return obj + "";
var reg = /^\[object ([a-zA-Z0-9]+)\]$/i;
return typeof obj === "object" || typeof obj === "function" ?
reg.exec(toString.call(obj))[1].toLowerCase() :
typeof obj;
};
// Check whether it is an array or a class array
function isArrayLike(obj) {
varlength = !! obj &&"length" in obj && obj.length,/ /!!!!! The value of the obj attribute is false and the value of the obj
type = toType(obj);
if (isFunction(obj) || isWindow(obj)) return false;
return type === "array" || length === 0| | -typeof length === "number" && length > 0 && (length - 1)) in obj;// Determine the class array && has the highest priority
}
/ / testing is a pure Object "class is directly under the Object | | Object. The create (null)"
var isPlainObject = function isPlainObject(obj) {
var proto, Ctor;
if(! obj || toString.call(obj) ! = ="[object Object]") return false;
proto = getProto(obj);
// Objects with no prototype (e.g., `Object.create( null )`) are plain
if(! proto)return true;
// Objects with prototype are plain iff they were constructed by a global Object function
Ctor = hasOwn.call(proto, "constructor") && proto.constructor;
return typeof Ctor === "function" && fnToString.call(Ctor) === ObjectFunctionString;
}
Call (Ctor) if these two are equal, fnToString.call(Object) is a pure Object
// Detect an empty object
var isEmptyObject = function isEmptyObject(obj) {
var keys = Object.keys(obj);
if (typeof Symbol! = ="undefined") keys = keys.concat(Object.getOwnPropertySymbols(obj));
return keys.length === 0;
};
// object.prototype. AA="AA" // empty Object
/ / {}
// Check if it is a number
var isNumeric = function isNumeric(obj) {
var type = toType(obj);
return (type === "number" || type === "string") &&!isNaN(obj); } </script>Copy the code