Skip to content

Instantly share code, notes, and snippets.

@ghelobytes
Created February 7, 2017 13:13
Show Gist options
  • Select an option

  • Save ghelobytes/f66c0b7d3f28d0bd1f928e0463252726 to your computer and use it in GitHub Desktop.

Select an option

Save ghelobytes/f66c0b7d3f28d0bd1f928e0463252726 to your computer and use it in GitHub Desktop.
Demonstrate scoping in JS
class Car {
constructor(make) {
this.make = make;
}
drive() {
console.log("Driving a " + this.make);
}
startIn(s) {
var car = this;
setInterval(function() {
car.start();
}, s);
}
start() {
console.log(this.make + " started!");
}
}
var a = new Car("Honda");
a.drive();
a.startIn(2000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment