Skip to content

Instantly share code, notes, and snippets.

@juwencheng
Created May 21, 2017 08:25
Show Gist options
  • Save juwencheng/e46ce70f5e0d6a6e1876433f80207ce6 to your computer and use it in GitHub Desktop.
Save juwencheng/e46ce70f5e0d6a6e1876433f80207ce6 to your computer and use it in GitHub Desktop.
simple demo shows usage of array function
let numbers = [2, 3, 4, 5, 6, 7]
let doubled = numbers.map((n) => n * 2);
console.log(doubled);
let person = {
name: 'Ryan',
hobbies: ['Robots', 'Computers', 'Internet'],
showHobbies: function() {
// this.name undefined
// this.hobbies.forEach(function(hobby){
// console.log(`${this.name} likes ${hobby}`
// })
this.hobbies.forEach(hobby => {
console.log(`${this.name} likes ${hobby}`
})
},
sayName() {
console.log(`Hi I am ${this.name}`);
}
}
person.sayName();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment