-
Notifications
You must be signed in to change notification settings - Fork 0
/
rabit.html
58 lines (33 loc) · 996 Bytes
/
rabit.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
<!DOCTYPE html>
<html>
<body>
<script>
var rabbit = {};
rabbit.speak = function(line) {
console.log("The rabbit says '", line, "'");
};
rabbit.speak("Well, now you're asking me.");
function speak(line) {
console.log("The ", this.adjective, " rabbit says '", line, "'");
}
var whiteRabbit = {adjective: "white", speak: speak};
var fatRabbit = {adjective: "fat", speak: speak};
whiteRabbit.speak("Oh my ears and whiskers, how late it's getting!");
fatRabbit.speak("I could sure use a carrot right now.");
speak.apply(fatRabbit, ["Yum."]);
speak.call(fatRabbit, "Burp.");
function Rabbit(adjective) {
this.adjective = adjective;
this.speak = function(line) {
console.log("The ", this.adjective, " rabbit says '", line, "'");
};
}
var killerRabbit = new Rabbit("killer");
killerRabbit.speak("GRAAAAAAAAAH!");
Rabbit.prototype.dance = function() {
console.log("The ", this.adjective, " rabbit dances a jig.");
};
killerRabbit.dance();
</script>
</body>
</html>