January 2020
Intermediate to advanced
470 pages
11h 13m
English
Let's go for a basic example. We could have a City class with name, latitude (lat), and longitude (long) attributes:
class City { constructor(name, lat, long) { this.name = name; this.lat = lat; this.long = long; } getName() { return this.name; } setName(newName) { this.name = newName; } setLat(newLat) { this.lat = newLat; } setLong(newLong) { this.long = newLong; } getCoords() { return [this.lat, this.long]; }}
This is a common class with a few methods; everything's quite normal. We could use this class as follows and provide details about my native city, Montevideo, Uruguay:
let myCity = new City("Montevideo, Uruguay", -34.9011, -56.1645);console.log(myCity.getCoords(), myCity.getName());// [ -34.9011, -56.1645 ] ...Read now
Unlock full access