Skip to content

Instantly share code, notes, and snippets.

@pepoviola
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pepoviola/fc4ae11b6b498cb11d82 to your computer and use it in GitHub Desktop.
Save pepoviola/fc4ae11b6b498cb11d82 to your computer and use it in GitHub Desktop.
Ejemplo herencia por prototipos
// base
var Padre = function(){
// atributos de la clase padre
this.yo = "soy el padre",
this.nacionalidad = "Argentino",
// metodos de la clase padre
this.saludar = function(){ alert(this.yo) },
this.donde = function(){ alert("soy "+ this.nacionalidad)}
}
var Hijo = function(){
// atributo de la clase hijo
this.yo = "soy el hijo"
}
// hereda el prototipo del padre
Hijo.prototype = new Padre();
// instancio
var padre = new Padre();
var hijo = new Hijo();
//overrides prototipe method
Hijo.prototype.donde = function(){ alert("Soy Uruguayo") }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment