Towards OOP in Vue.js
Exporting your class
export default class Weapon{
constructor(val, type)
{
this.val = val;
this.family = type;
}
}import Weapon from "./my/path/Weapon.js"; //Weapon variable is available, we can construct new weapon is `new`
export default class NPC{ //don't forget to export this class too!
constructor()
{
this.weapons = [];
this.weapons[0] = new Weapon(5,"bamboo"); //new instance of weapon!
}
pickWeapon(wpn)
{
this.weapons.push(weapons);
}
throwWeapon()
{
this.weapons.pop();
}
}Last updated
Was this helpful?