Created
February 7, 2017 13:13
-
-
Save ghelobytes/f66c0b7d3f28d0bd1f928e0463252726 to your computer and use it in GitHub Desktop.
Demonstrate scoping in JS
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
| 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