Javascript uses prototypical inheritance. "class" is just an es6 syntax sugar of prototypical inheritance. I would first learn about it first via some simple youtube search. In short, my suggestion is to familiarize yourself with Javascript's prototypical inheritance first before jumping into classes.
Sometimes classes can be hard to implement.
Like Robert's example. Sometimes it just feels weird to create a base class for the sheer reason to incorporate the classes below it.
I want a wizard and I want a monster and they can both shoot lightnings. But do I really need to think of a 'base class' where shootLightning is a property? Other than shooting lightnings and maybe 1-2 other features, wizards aren't really monsters... they just happen to share a few things in common.
We can take advantage of Javascript's prototypical inheritance.
//First we create a 'prototype', which are basically objects.
const monsters = {
type : "monster"
}
const wizards = {
type : "wizard"
}
//Later on we can define properties. This is good because later on in the dev cycle we can come up with new properties.
const ability_lightning = function() {
console.log("I shoot lightning! pew!")
}
// Lets say now I want to assign my ability to both monsters and wizards.
// I can now do:
Object.assign(monsters, {lightning : ability_lightning })
Object.assign(wizards, {lightning : ability_lightning })
// I can create instances
const godzilla = Object.create(monsters)
godzilla.lightning()
//I shoot ligntning!
const gandalf = Object.create(wizards)
console.log(gandalf.type) //wizard
EDIT:
As for your error, I believe it is because you didn't export in your first file.