Performing inheritance in JavaScript -


Now that I know that you can not show your heritage in C #, I have seen it on the Internet It is possible that if it is not possible to use plain javascript code, will it be possible to use it, and if so how?

Javascript object-oriented paradigm is there are no "classes", just objects

You can apply heritage in different ways. Two more popular options are "pseudo-classical" and "prototype" forms. For example:

pseudo-classical heritage

I think this is the most popular way. You use it with that operator, and you add members through the constructor function prototype.

  // Define the person constructor function function person () {} Person.prototype.sayHello = function () {Warning ('hello'); }; // Student Constructor Function Define the Student Definition () {} // The succession to the individual student. Protopp = new person (); // Correct the constructor pointer because this person tells the student. Prototype .constructor = student; // say hello method change (a multicast example) Student.prototype.sayHello = function (warnings ('Hi, I am a student'); } Var student1 = new student (); Student1.sayHello (); Actually, we create an auxiliary function that takes the object as a parameter and returns an empty object obtained from the old empty,  Objects object .  
  // helper object if (type of object! Create! == 'function') {Object.create = function (o) {function F () {} F .prototype = o; Return new F (); }; } Var person = {sayHello: function () {warning ('person object'); }, Move: function () {alert ('walk'); }}; Var student1 = Object Create (person); Student1.sayHello = Function () {Warning ('Hello I am a student'); };  

Another interesting form is the parasitic heritage in the "derivative" constructor you make a "base" object example. That object is enlarged and this new example returned:

  // person constructor function function person (name) {this.name = name; } Function student (value) {var that = new person (value); That.sayHello = ceremony () {Warning ('Hello I am a student'); }; That return; }  

Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -