This is the original prototype of Js.

Source: Internet
Author: User
This is the original prototype of Js.

This is the original prototype of Js.
1. An object must have the ability to inherit, which is like a universal
2. An object must be expressive.CodeWriting this capability is also important
3. Construct a Web element
This is a definition:
Function person (first_name, family_name ){
This. Name = function () {return this. family_name + ''+ this. first_name ;}
This. setname (first_name, family_name );
}
Now let this object be expressed:
// Required methods for setting attributes
Person. Prototype. setname = function (F1, F2 ){
If (! This. first_name) This. first_name = F1;
If (! This. family_name) This. family_name = F2; // you can change the name of your sitting name.
}
// He will give his name
Person. Prototype. tostring = function () {return 'I \ 'M' + this. Name ();}

now, this prototype is extended to construct a new object.
function teacher (first_name, family_name) {
This. job = 'teacher';
This. setname (first_name, family_name);
}< br> // so that he is a person
teacher. prototype = new person;
// different people may say different things
teacher. prototype. tostring = function () {return 'I \'m is a teacher, I \'m name is' + this. name ()}
in this way, this object is also expressive.
therefore, it is called the web expression capability, that is, the previous object can be passed through document. write (), or alert () and other true output object descriptions.
for Weg elements, this re-expression capability is very important. Because, HTML
function element ()
{< br> This. html = "";
}< br> element. prototype. tostring = function () {return this. HTML ;}< br> button. prototype = new element;
function button (Caption, event)
{< br> This. caption = Caption;
This. event = event;
This. html = '' + this. caption + '';
}< br> T = new button ('button1', 'alert (this. innertext) ');
document. write (t);

This is just a simple element, but it can also be used to construct more complex Web controls.

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.