generated from coyotiv/stack
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprevious-classes.js
59 lines (52 loc) · 1.25 KB
/
previous-classes.js
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
class User {
profilePicture = ''
bio = ''
location = ''
website = ''
createdAt = new Date()
followers = []
following = []
tweets = []
likedTweets = []
tweet(tweet) {
this.tweets.push(tweet)
}
follow(user) {
this.following.push(user)
user.followers.push(this)
}
like(tweet) {
this.likedTweets.push(tweet)
tweet.likes.push(this)
}
retweet(originalTweet, body = '') {
const retweet = new Tweet(body, this)
retweet.originalTweet = originalTweet
this.tweets.push(retweet)
originalTweet.retweets.push(retweet)
}
constructor(name, handle, email) {
this.name = name
this.handle = handle
this.email = email
}
}
class Tweet {
createdAt = new Date()
replies = []
likes = []
retweets = []
originalTweet = null
attachments = []
constructor(body, author) {
this.body = body
this.author = author
}
}
const dashersw = new User('Armagan Amcalar', '@dashersw', '[email protected]')
const pcultural = new User('Paloma Oliveira', '@pcultural', '[email protected]')
const tweet1 = new Tweet('Hello, world!', pcultural)
pcultural.tweet(tweet1)
dashersw.retweet(tweet1, "Look at who's here! Welcome @pcultural")
dashersw.like(tweet1)
console.log(dashersw, pcultural)