When defining a class in ES6, it becomes available in the global scope, which you can prevent with the new ES6 bracket enclosure:
{
class Car {
constructor(make) {
this.make = make;
this.currentSpeed = 25;
}
getSpeed(){
console.log(this.make + ' is going ' + this.currentSpeed + ' mph.');
}
}
window.MYNAMESPACE.Car = Car;
}
I have multiple js files, each with their own class definition, and I make the classes available via MYNAMESPACE in the global scope. So creating a new car from anywhere looks like:
var myCar = new MYNAMESPACE.Car();
How could I use ES6 modules for this? Is that even possible, or recommendable?