Class Inheritance in Javascript -


I'm thinking how to emulate class inheritance in JavaScript. I know that the class does not apply to javascript, the way we use it is to create objects and do legacy through prototype objects. For example, how do you convert this structure to javascript:

  public class human race {name of the public string; Public string last name; } Public class person: Mankind {public wired run (what is the string) {// write logic}}  

What is the equivalent of this piece of code in JavaScript?

Edit:

I have also found another link where Douglas Crockford describes different heritage models:

Hope it helps others too.

There are several ways to apply inheritance and behavior reuse in JavaScript, perhaps by way of more The same would be a pseudo-classical legacy for its class based OOP example:

  Function Mankind (name, last name) {this.name = name; This .lastname = lastname; } Function person (name, last name) {this.name = name; This .lastname = lastname; This.run = function () {// run logic}; } Person.prototype = New Mankind (); Person.prototype.walk = function () {// Run logic}; The difference between   

running and walking is that each object of the first person will be present on the instance , And the second method, running , will only be present in person.prototype and through the prototype series.

In this pattern you will see a bit of code duplication, we need logic to initialize the fields on the inherited constructor, the second pattern which avoids it, is the constructor function application:

  function mankind (name, last name) {this .name = name; This .lastname = lastname; } Function person (name, last name) {Mankind.Apple (this, argument); This.run = function () {// run logic}; (Article)  
  • (article)
  • More information:

    • (different examples)
    • / li >

    Comments

    Popular posts from this blog

    oracle - The fastest way to check if some records in a database table? -

    php - multilevel menu with multilevel array -

    jQuery UI: Datepicker month format -