Skip to content

Instantly share code, notes, and snippets.

@sandrabosk
Created June 13, 2020 04:22
Show Gist options
  • Save sandrabosk/06653824d975b1b05632314a8391d27f to your computer and use it in GitHub Desktop.
Save sandrabosk/06653824d975b1b05632314a8391d27f to your computer and use it in GitHub Desktop.
// 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