-
Notifications
You must be signed in to change notification settings - Fork 0
/
objeto.html
50 lines (42 loc) · 1.36 KB
/
objeto.html
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
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Objetos</title>
</head>
<body>
<script type="text/javascript">
var myFilm = new Object();
myFilm.director = "Benito Camela";
myFilm.year ="2561";
myFilm.country = "Croatia";
myFilm["locura"] = "mucha";
function showProps (obj, objName){
var result = '';
for(var i in obj){
if(obj.hasOwnProperty(i)){
//esta propiedad pregunta si el objeto tiene esa propiedad
result+= objName + "." + i + "=" + obj[i] + "\n";
}
}
return result;
}
console.log(showProps(myFilm,"myFilm"));
document.write(showProps(myFilm,"myFilm"));
//otra forma loca de crear objetos
let altaPeli = {
año: "215",
director: "to3",
}
//una forma aun mas loca que implica una funcion
function peli(director,genero,estrella){
this.director = director;
this.genero = genero;
this.estrella = estrella;
}
var laMomia = new peli("Jonathan Rodriguez", "Terror Marxista", "tita");
var barcoDeAmor = new peli("Norberto","Aventura acuatica","loco");
document.write(showProps(laMomia,"laMomia"));
</script>
</body>
</html>