//default.js
const item = require("./item.js");
var itemTest = new item.ItemTest("weapon",1,1,1);
console.log(itemTest.name);
//item.js
module.exports = class ItemTest {
constructor(name, value, attack, defense) {
this.name = name;
this.value = value;
this.attack = attack;
this.defense = defense;
}
}
I've also tried it with simply
//item.js
function ItemTest(name, value, attack, defense) {
this.name = name;
this.value = value;
this.attack = attack;
this.defense = defense;
}
but that also returns "item.ItemTest is not a constructor". if that function is added into default.js then it works just fine, but I don't know how to make it pull the constructor object from the other file.
var itemTest = new item("weapon",1,1,1);(You're exporting theclass, so in default.js,itemis the class; just imagine whatever you're setting tomodule.exportsis what replacesrequire())module.exportsIS what you get when you dorequire()of that module. So when you doconst Item = require('./item.js');, thenItemis yourclassthat you exported so you'd just donew Item().