Created
June 19, 2013 07:33
-
-
Save ricardosiri68/5812315 to your computer and use it in GitHub Desktop.
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
// definimos el Primer Objeto: | |
// Este va a ser la raiz el objeto del que se van a basar los que le sigan | |
var Obj = function(name){ | |
this.getName = function(){ | |
return this.name; | |
} | |
this.setName = function(name){ | |
this.name = name | |
} | |
this.setName(name); | |
} | |
// definimos el Segundo Objeto; | |
// no contento con las caracteristicas del primero creamos un objeto con otros atributos | |
var Obj2 = function(name, age){ | |
// como en la linea 29 se alcanza a observar | |
// este objeto extiende al Primero de ahi | |
this.constructor(name); // que constructor resiva el parametro name, | |
//por que asi se construye el primer objeto | |
// se le añaden nuevos metodos y a otra cosa mariposa | |
this.getAge = function(){ | |
return this.age; | |
} | |
this.setAge = function(age){ | |
return this.age = age; | |
} | |
this.setAge(33); | |
} | |
Obj2.prototype = new Obj(); // y aca extendemos el primer Objeto hacia el segundo | |
// solo con intencion de demostrar que como cualquier lenguaje de programacion | |
// que afirma soportar el paradigma de programacion orientada a objetos | |
// creamos el Tercer Objeto que va extender al segundo, creando asi nuestro primer | |
// arbol de dependencias :3 | |
var Obj3 = function(name,age,wieght){ | |
this.constructor(name,age); | |
this.getWieght = function(){ | |
return this.wieght; | |
} | |
this.setWieght = function(wieght){ | |
this.wieght = wieght; | |
} | |
this.setWieght(wieght); | |
} | |
Obj3.prototype = new Obj2(); // bien aca muestra como se extiende el Segundo hacia el Tercero | |
obj = new Obj("smokeweed46"); // contruimos el primer objeto | |
console.log(obj.getName()); // lo revisamos | |
obj.setName("richar"); // redefinimos su unico atributo | |
console.log(obj.getName()); // y comprobamos que hizo el trabajo | |
// Segundo objeto con mas parametros y le hacemos las mismas pruebas que al primero | |
obj2 = new Obj2("manolo12",33); | |
console.log(obj2.getName(), obj2.getAge()); | |
obj2.setName("erni"); | |
obj2.setAge(3); | |
console.log(obj2.getName(), obj2.getAge()); | |
// Tercer Objetos con aun mas parametros en su contruccion y le hacemos la suma de todas la pruebas | |
obj3 = new Obj3("bruce waine",30,80); | |
console.log(obj3.getName(), obj3.getAge(), obj3.getWieght()); | |
obj3.setName("batman"); | |
// es el mayor el peso del traje con el sinturon lleno de porquerias re zarpadas | |
obj3.setWieght(obj3.getWieght() + 15); | |
// mostramos otra vez | |
console.log(obj3.getName(), obj3.getAge(), obj3.getWieght()); | |
// y para los incredulos la instancia del Primer y Segundo Objeto completamente intactas | |
console.log(obj.getName()); | |
console.log(obj2.getName(), obj2.getAge()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment