Skip to content

Instantly share code, notes, and snippets.

@vmarchesin
Last active September 11, 2018 21:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vmarchesin/12aeffeaeeeb663ad8bbaa9402349747 to your computer and use it in GitHub Desktop.
Save vmarchesin/12aeffeaeeeb663ad8bbaa9402349747 to your computer and use it in GitHub Desktop.
Javascript Arrow Function and Closure
class Dog {
constructor(name) {
this.name = name
}
bark() {
console.log(`Woof, my name is ${this.name}`);
}
sitAndBark() {
setTimeout(function() { console.log(`Woof, my name is ${this.name}`) }, 1000)
}
}
let rex = new Dog('Rex')
rex.bark()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment