Object.extend=function(destination, source) {
for(varPropertyinchSOURCE) {
Destination[property] = Source[property];
}
returnDestination
} Prototype the object class is extended primarily through a static function
Object.extend(destination, source) implements the
JavaScriptInheritance in the. From a semantic point of view,
Object.extendThe (destination, source) method is somewhat illogical because it actually only implements a holographic copy from the source object to the target object. But you can also think of this: because the target object has all the attributes owned by the source object, it looks like the target object inherits the source object (and expands it). In addition, prototype extends several more useful static methods to object, and all other classes can obtain support by invoking these static methods.
JScript Code
Object.extend=function(destination, source) {//A static method represents inheritance, and the target object will have all the properties and methods of the source object
for(varPropertyinchSOURCE) {
Destination[property] = Source[property];//Dynamically adding properties and methods by assigning values using the characteristics of dynamic languages
}
returnDestination//returning an extended object
}
Object.extend(Object, {
Inspectfunction(object) {//a static method that passes in an object that returns a string representation of the object
Try{
if(object = = undefined)return' Undefined ';//Handling undefined situations
if(Object = =NULL)return' NULL ';//Handling NULL Cases
//if the object defines the inspect method, call the method to return, otherwise return the object's ToString () value
returnObject.inspect? Object.inspect (): Object.ToString ();
}Catch(e) {
if(EinstanceofRangeerror)return‘...‘;//Handling Exception Conditions
ThrowE
}
},
Keysfunction(object) {//a static method that passes in an object that returns all of the properties of the object, constituting the array returned
varKeys = [];
for(varPropertyinchObject
Keys.push (property);//press each property into an array
returnKeys
},
Valuesfunction(object) {//a static method that passes in an object that returns the values of all the properties in the object, constituting the array returned
varvalues = [];
for(varPropertyinchObject) Values.push (Object[property]);//presses the value of each property into an array
returnValues
},
Clonefunction(object) {//a static method, passing in an object, cloning a new object and returning
return
Object.extend({}, object);
}
});