Created
September 18, 2019 16:10
-
-
Save martinlaws/dda72364782c84622d8bdd5cfae756d0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const person = { | |
firstName: 'Martin', | |
lastName: 'Laws', | |
heightInCm: 188, | |
heightInInches: function() { | |
return this.heightInCm / 2.54 | |
}, | |
speak() { | |
console.log(`Hi, my name is ${this.firstName}!`) | |
return | |
}, | |
friends: [] | |
} | |
person.heightInInches() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Person(firstName, lastName, heightInCm) { | |
this.firstName = firstName | |
this.lastName = lastName | |
this.heightInCm = heightInCm | |
this.friends = [] | |
this.addFriend = function(friend) { | |
if (typeof friend === 'object') { | |
this.friends.push(friend) | |
} else { | |
console.log('GO GET A REAL FRIEND!') | |
} | |
} | |
this.fullName = function() { | |
console.log(`${this.firstName} ${this.lastName}`) | |
} | |
this.heightInInches = function() { | |
return this.heightInCm / 2.54 | |
} | |
this.speak = function() { | |
console.log(`Hi, my name is ${this.firstName}!`) | |
return | |
} | |
} | |
const martin = new Person('Martin', 'Laws', 188) | |
const scott = new Person('Scott', 'Morrison', 189) | |
martin.addFriend(scott) | |
martin.addFriend(123) | |
// scott.friends.push(martin) | |
console.log('Martin:', martin) | |
console.log('Scott:', scott) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment