The JavaScript base class contains basic methods _js object-oriented

Source: Internet
Author: User
Copy code code as follows:

<script type= "text/javascript" >
function Base () {}//Root abstract class
Base . Tobase=function () {//method to convert an object to an instance of the Base class
return new Base ();
}
Base.inherit=function (parent) {//method for inheriting an instance of the Base class
var f=function () {}
F.prototype=parent;
return new F;
}
Base.prototype.extend = function (prop) {//extension root abstract class Base extend method
for (Var o in prop) {
This[o] = Prop [O];
}
}
Base.prototype.method = function (name, FN) {//extension root abstract class Base method
This[name] = fn;
return this;
}
Var o=new base ();////Create a base instance
O.method ("show", the function () {//To add to the object "O"-Method
Alert ("Show function");
});
O.extend ({//The Add Name property and say function to object o
Name: "Shupersha",
Say:function () {
Alert ("Say Function")
} br>});
var t=base.inherit (o);//Inheritance O object's properties and Methods
T.show ();
T.say ();
</script>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.