forked from michiganhackers/javascript-talk
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path8.js
More file actions
46 lines (27 loc) · 734 Bytes
/
8.js
File metadata and controls
46 lines (27 loc) · 734 Bytes
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
// simple design overview
function Person(n,a,g) {
this.name = n;
this.age = a;
this.gender = g;
this.friends = [];
this.becomeFriend = function(friend) {
this.friends.push(friend);
friend.friends.push(this);
}
this.showFriends = function() {
console.log(this.name + "'s friends:")
for (var i in this.friends)
console.log(this.friends[i]);
}
}
// somewhere else ...
var otto = new Person("otto", 22, "M");
var sam = new Person("sam", 22, "M");
otto.becomeFriend(sam); // whats this do?
otto.showFriends();
sam.showFriends();
// add methods after the fact
otto.giveTalk = function() {
console.log("JS! Blah blah!");
};
otto.giveTalk();