| 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. |