-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprototipos.html
More file actions
26 lines (21 loc) · 1.04 KB
/
prototipos.html
File metadata and controls
26 lines (21 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<script type="text/javascript">
console.log( Array.prototype == Object.getPrototypeOf( [] ) );// El prototipo de un array es igual a Array.prototype
console.log( Function.prototype == Object.getPrototypeOf( isNaN ) );// El prototipo de una funcion es igual a Function.prototype
function persona( ci, nom, ape){
this.ci= ci;
this.nombre= nom;
this.apellido= ape;
}
function a_string(){// Este metodo sobreescribe el metodo estandar toString del prototipo
console.log( this.nombre, " ci ", this.ci );
}
/** Las nuevas propiedades y metodos deben definirse a traves del nombre_de_constructor.prototype.nuevo_metodo_o_propiedad**/
persona.prototype.toString= a_string;
persona.prototype.sexo= "Femenino";
persona.prototype.genero= function(){ console.log( "Es ", ( this.sexo=="Femenino")?"mujer":"hombre" ); };
persona.prototype.nacionalidad= "Paraguaya";
var yo= new persona("4747132","Sonia","Toledo");
yo.toString();// Llamada al metodo toString propio del objeto persona y no del prototipo
yo.genero();
console.log( yo.nacionalidad );
</script>