How to make inheritance with Javascript / jQuery

Asked

Viewed 92 times

1

I have a question about how to use inheritance with Javascript / jQuery (if possible), I did a search but found confusing materials of gringos who could not help me.

Let’s go to the classic example of Person / Personal.

// Arquivo PessoaModal.js
var Pessoa = function(id , nome , status){
  this.id = id;
  this.nome = nome;
  this.status = status;
};

Pessoa.prototype = {
  getId : function(){
    return this.id;
  } ,
  setId : function(id){
    this.id = id;
  } ,
  getNome : function(){
      return this.id;
  } ,
  setNome : function(nome){
    this.nome = nome;
  } ,
  getStatus : function(){
      return this.id;
  } ,
  setStatus : function(status){
    this.status = status;
  } ,
  __get : function(propriedade){
    return this[propriedade];
  } ,
  __set : functoin(propriedade , valor){
    this[propriedade] = valor;
}

// PessoaFisicaModal
var PessoaFisica = function(rg , cpf){
  this.rg = rg;
  this.cpf = cpf;
};

PessoaFisica.prototype = {
  getRg : function(){
    return this.rg;
  } ,
  setRg : function(rg){
    this.rg = rg;
  } ,
  getCpf : function(){
    return.cpf;
  } ,
  setCpf : function(cpf){
    this.cpf = cpf;
  } ,
  __get : function(propriedade){
    return this[propriedade];
  } ,
  __set : function(propriedade , valor){
    this[propriedade] = valor;
  }
};




  

in the above example, how would Pessoafisica inherit the properties and methods of Pessoamodal (Superclass) ?

  • 3

    I suggest you take a look at this link http://answall.com/questions/7220/este-%C3%A9-an-example-correct-de-heran%C3%A7a-in-javascript. There is how your question can be answered, or at least give a light to what you need

  • jQuery does not give: http://answall.com/q/46983/101

  • Very good the suggested explanation, now I can use all my SUPERCLASSS methods for daughters. Congratulations @Ricardo Lucas.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.