I have some experience with C# and Java, but I'm trying to learn javascript/node.js. I can't quite figure out what the problem is with this code.
So I have my main.js
file, and it has this code:
const MyClass = require("./MyClass");
let myclass = new MyClass("my string!");
myclass.repeatString();
The MyClass
it's calling has this code:
class MyClass {
constructor(myString) {
this.myString = myString;
}
repeatString() {
console.log(myString);
}
}
module.exports = MyClass;
When I try to run this, I get ReferenceError: myString is not defined
when it tries to execute that repeatString()
method. What am I doing wrong/what's the right way to do this?