Created
March 15, 2015 19:43
-
-
Save jamc92/dd88ea2b070d21b30a2f to your computer and use it in GitHub Desktop.
JS - Inheritance with prototype
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Prototype Inheritance</title> | |
<script type="text/javascript"> | |
function Domestico() { | |
this.animal = ""; | |
this.nombre= ""; | |
this.configurarAnimal = function(nuevoAnimal) { | |
this.animal = nuevoAnimal; | |
} | |
this.configurarNombre= function(nuevoNombre) { | |
this.nombre = nuevoNombre; | |
} | |
} | |
var miGato = new Domestico(); | |
miGato.ConfigurarAnimal = "gato"; | |
miGato.ConfigurarNombre = "Silvestre"; | |
Perro.prototype = new Domestico(); | |
function Perro() { | |
this.raza = ""; | |
this.configurarRaza = function(nuevaRaza) { | |
this.raza = nuevaRaza; | |
} | |
this.mostrarInfo = function() { | |
alert(this.nombre + " es un " + this.raza); | |
} | |
} | |
var miPerro = new Perro(); | |
miPerro.configurarNombre("Montano"); | |
miPerro.configurarRaza("San Bernardo"); | |
</script> | |
</head> | |
<body> | |
<input type="button" value="Mostrar info" onclick="miPerro.mostrarInfo()" /> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment