Skip to content

Instantly share code, notes, and snippets.

@glaszczak
Created April 27, 2020 18:02
Show Gist options
  • Save glaszczak/5cd3f7c8222fecca2cd26bae7a9209da to your computer and use it in GitHub Desktop.
Save glaszczak/5cd3f7c8222fecca2cd26bae7a9209da to your computer and use it in GitHub Desktop.
class Me {
constructor(userName, friend) {
this.userName = userName;
this.friend = friend;
}
getName() {
console.log(`This is ${this.userName}`);
}
getFriend() {
console.log(this.friend);
}
}
class Friend {
constructor(friendName, otherFriend) {
this.friendName = friendName;
this.otherFriend = otherFriend;
}
static logFriendName() {
console.log(this.friendName);
}
logOtherFriend() {
console.log(this.otherFriend);
}
}
class OtherFriend {
constructor(otherFriendName) {
this.otherFriendName = otherFriendName;
}
logOtherFriendName() {
console.log(this.otherFriendName);
}
}
const me = new Me("Me", new Friend("Friend", new OtherFriend("Other Friend")));
me.getFriend(); // returns: Friend {friendName: 'Friend', otherFriend: OtherFriend { otherFriendName: 'Other Friend' } }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment