-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtemplate-pattern.html
55 lines (44 loc) · 1.18 KB
/
template-pattern.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Demo Template Pattern</title>
<script type="text/javascript">
function Vehicle() {
this.run = function() {
this.prepare();
this.move();
};
this.prepare = function () {}
this.move = function () {}
}
function Car() {
this.prepare = function() {
document.write("Start car engine <br/>");
}
this.move = function() {
document.write("Drive the car <br/>");
}
this.__proto__ = new Vehicle();
}
function Yacht() {
this.move = function() {
document.write("Sail the yacht <br/>");
}
this.__proto__ = new Vehicle();
}
</script>
</head>
<body>
<script type="text/javascript">
var car = new Car();
car.run();
document.write("<br/>");
var yacht = new Yacht();
yacht.run();
document.write("<br/>");
yacht.prepare = function() { document.write('Hoist the sails <br/>') };
yacht.run();
</script>
</body>
</html>