Copy codeThe Code is as follows:
<Script type = "text/javascript">
Function Base () {}// root abstract class
Base. toBase = function () {// Method for converting an object into an instance of the Base class
Return new Base ();
}
Base. inherit = function (parent) {// method used to inherit the Base class instance
Var F = function (){}
F. prototype = parent;
Return new F;
}
Base. prototype. extend = function (prop) {// extended root abstract class Base's extend Method
For (var o in prop ){
This [o] = prop [o];
}
}
Base. prototype. method = function (name, fn) {// method for extending the Base of the root abstract class
This [name] = fn;
Return this;
}
Var o = new Base (); // create a Base instance
O. method ("show", function () {// Add the show method to object o
Alert ("show function ");
});
O. extend ({// Add the name attribute and the say function to the object o
Name: "shupersha ",
Say: function (){
Alert ("say function ")
}
});
Var t = Base. inherit (o); // inherits the attributes and methods of the o object
T. show ();
T. say ();
</Script>