//Create an Object object through anonymous function calls
(function() {
//Get the string expression form of type, (Prototype learning - tool function learning ($ method)) There is a detailed description in this log.
function getClass(object) {
return (object)
.match(/^\[object\s(.*)\]$/)[1];
}
//Inheriting method, a very simple class copying mechanism, which is to copy all attributes and methods in source into destination. If it is a reference type, source and destination will point to the same address
function extend(destination, source) {
for (var property in source)
destination[property] = source[property];
return destination;
}
//Return the string expression form of object
function inspect(object) {
try {
if (isUndefined(object)) return 'undefined';
if (object === null) return 'null';
return ? () : String(object);
} catch (e) {
if (e instanceof RangeError) return '...';
throw e;
}
}
//Return the object's JSON (JavaScript Object Notation)
function toJSON(object) {
var type = typeof object;
switch (type) {
case 'undefined':
case 'function':
case 'unknown': return;
case 'boolean': return ();
}
if (object === null) return 'null';
if () return ();
if (isElement(object)) return;
var results = [];
for (var property in object) {
var value = toJSON(object[property]);
if (!isUndefined(value))
(() + ': ' + value);
}
return '{' + (', ') + '}';
}
//Return the query string, for example: param1=value1¶m2=value2
function toQueryString(object) {
return $H(object).toQueryString();
}
//Return HTML string
function toHTML(object) {
return object && ? () : (object);
}
//Get all keys of the object
function keys(object) {
var results = [];
for (var property in object)
(property);
return results;
}
//Get all values of the object
function values(object) {
var results = [];
for (var property in object)
(object[property]);
return results;
}
//Copy all properties and methods in the object into an empty object and return
function clone(object) {
return extend({ }, object);
}
//Judge whether the object is a basic DOM Element
function isElement(object) {
return !!(object && == 1);
}
//Judge whether the object is an array
function isArray(object) {
return getClass(object) === "Array";
}
//Judge whether the object is a Hash object of Prototype
function isHash(object) {
return object instanceof Hash;
}
//Judge whether object is a function
function isFunction(object) {
return typeof object === "function";
}
//Judge whether the object is a string
function isString(object) {
return getClass(object) === "String";
}
//Judge whether the object is a number
function isNumber(object) {
return getClass(object) === "Number";
}
//Judge whether the object has been defined
function isUndefined(object) {
return typeof object === "undefined";
}
//Return the Object object
extend(Object, {
extend: extend,
inspect: inspect,
toJSON: toJSON,
toQueryString: toQueryString,
toHTML: toHTML,
keys: keys,
values: values,
clone: clone,
isElement: isElement,
isArray: isArray,
isHash: isHash,
isFunction: isFunction,
isString: isString,
isNumber: isNumber,
isUndefined: isUndefined
});
})();