Created
June 13, 2020 04:22
-
-
Save sandrabosk/06653824d975b1b05632314a8391d27f 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
// declaring objects: | |
// as objects literals: | |
const product = {name:'iphone', price: 799.99} | |
// console.log(product); | |
// using the keyword new: | |
const book = new Object(); | |
book.title = 'ana karenina'; | |
book.author = 'leo tolstoy'; | |
// console.log(book); | |
const person = { | |
name: 'Jose', | |
age: 26, | |
greet: function () { | |
console.log('Hello!'); | |
}, | |
getName: function () { | |
console.log(`My name is ${this.name}.`); | |
}, | |
// The ES6 way wouldn't bind the "this" keyword | |
// to the object | |
// sayName: () => { | |
// console.log('My name is ' + this.name); | |
// }, | |
sayHappyBirthday: function(){ | |
setInterval(() => { | |
console.log(`Happy Birthday! You are now ${this.age += 1}. `) | |
}, 1000) | |
} | |
}; | |
person.greet(); | |
person.getName(); | |
person.sayHappyBirthday(); | |
// πππ EXERCISE - Chuck Norris |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment