JavaScript object-oriented (2)

Source: Internet
Author: User

I wrote too much nonsense in the previous article and it was very bad to write. Let's talk about inheritance this time. We learned prototype in the previous section. Now I am going to start with prototype to implement it.

<Scr limit pt LANGUAGE = "Limit Cr limit pt">
<! --
Function occupation (){
Var notice = "work well every day ";
}
Occupation. prototype. Work = function (name ){
Return name + "work ";
}
Occupation. prototype. Off duty = function (){
Return "off duty ";
}
Function. prototype. extend = function (superClass ){
For (var $ p in superClass. prototype ){
This. prototype [$ p] = superClass. prototype [$ p];
}
Delete $ p;
}
Function actor (){
}
Actor. prototype. Television = function (person ){
Return person + "TV ";
}
Function clown (){
}
Clown. prototype. Line header = function (){
Return "exaggerated smile ";
}

Actor. extend (occupation );

Var Zhang San = new actor ();

Alert (Zhang San. Go to work ("Zhang San "));

Clown. extend (actor );

Var xiaozhuo = new clown ();

Alert (xiaozhuo. Go to work ("xiaozhuo "));

Alert (xiaozhuo. Line header ());

Alert (xiaozhuo. TV ("xiaozhuo's show "));
// -->
</Scr platinum pt>


Only a small example of inheritance is written.

In this way, it is a bit difficult to do this without considering the parent class method and subclass method. Write to this

Later.

Related Article

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.