-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathset_get.html
More file actions
58 lines (41 loc) · 1.91 KB
/
set_get.html
File metadata and controls
58 lines (41 loc) · 1.91 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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<script type="text/javascript">
function persona(){
}
// indicando solo el ident. de constructor, omitiendo el .prototype
//creando propiedades del objeto
Object.defineProperty( persona, "nombre", {enumerable: true, value:"****"});
Object.defineProperty( persona, "apellido", {enumerable: true, value:"****"});
Object.defineProperty( persona , "ciudad", {enumerable: true, value:"****"});
Object.defineProperty( persona, "sexo", {enumerable:true, value:"x"});
// Definiendo propiedades funciones para getter setter se debe indicar el constructor con prototipo
Object.defineProperty( persona.prototype, "Sexo",
{ get: function(){ return (this.sexo=="F")? "Mujer": "Hombre"; },
set: function( v ){ this.sexo= v;} } );
Object.defineProperty(persona.prototype, "Fullname",
{ get: function(){ return this.nombre+" "+this.apellido ;} } );
var juanito= new persona();
juanito.nombre= "JUan"; juanito.apellido= "De La Mancha";
juanito.ciudad= "Madrid";
juanito.Sexo="M";
//Creando una nueva propiedad
juanito['direccion']="lomas";
//Creando una propiedad en el prototipo
persona.prototype.anios= 42;
//creando una propiedad no enumerable para el objeto
Object.defineProperty( persona, "edad", {enumerable: false, value:"nada"} );
console.log("Nombre completo", juanito.Fullname, " es ", juanito.Sexo );
console.log("listando las propiedades enumerables");
console.log("Obs: se listan las propiedades del objeto cuyo valor ha sido asignado");
for( var it in juanito){
console.log( "Propia : ", juanito.hasOwnProperty( it ) );
console.log( it ," : ", juanito[it]);
}
console.log("listando las propiedades no enumerables del obj." );
for( var ele in Object.keys( juanito ) ){
console.log( ele ," : ", juanito[ ele]);
}
console.log("listando las propiedades del prototipo", Object.getPrototypeOf( juanito ) );
for( var ele in Object.getPrototypeOf( juanito ) ){
console.log( ele ," : ");
}
</script>