-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheredar.html
64 lines (47 loc) · 1.41 KB
/
heredar.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<!DOCTYPE html>
<html lang="es">
<!--
NOMBRE ARCHIVO: prototipo.html
CREADOR: Isabel Ródenas
FECHA CREACIÓN: 05/03/2021
FECHA ÚLTIMA MODIFICACIÓN: 05/03/2021
OBJETIVO: Comprobar los prototipos
-->
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="styles/generico.css">
<title>objetos</title>
</head>
<body>
<script>
/* Declaración de variables */
var Vehiculo = function () {}
Vehiculo.prototype.acelerar = function () {
document.write('acelera<br>')
}
Vehiculo.prototype.frenar = function () {
document.write('frena<br>')
}
var Coche = function () {}
/* Copia atributos y métodos */
for (clave in Vehiculo.prototype) {
Coche.prototype[clave] = Vehiculo.prototype[clave];
}
Coche.prototype.frenar = function(){
document.write('frenar<br>')
}
var simca1100 = new Coche();
simca1100.acelerar();
simca1100.frenar();
Vehiculo.prototype.aparcar = function(){
document.write('aparca<br>');
}
/* Como se ha creado el método en el prototipo de Vehiculo después de heredar, no lo encuentra */
simca1100.aparcar();
</script>
<br /><br /><br />
<center>
<a href="Javascript:window.location='view-source:' + window.location">Código fuente</a>
</center>
</body>
</html>