Last active
August 29, 2015 14:01
-
-
Save pepoviola/fc4ae11b6b498cb11d82 to your computer and use it in GitHub Desktop.
Ejemplo herencia por prototipos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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