JSFiddle - React, Tailwind, and code Playground
by stot
JavaScript
// define base class with functions
skill = function (o) {
this.o = o
};
skill.prototype.update = function () {
console.log('default update called: o = ' + this.o);
};
var s = new skill('s');
s.update();
// extend base class with specific functions
MonsterSkillAttack = function (o) {
skill.call(this, o);
this.update = function () {
console.log('msa update called: o = ' + this.o);
}
}
MonsterSkillAttack.prototype = Object.create(skill.prototype);
// instantiate msa
var msa = new MonsterSkillAttack('i');
msa.update();
MonsterSkills = {
get: function (id) {
var skill = new window[this.skillStore[id]](id);
return skill;
},
/**
* the skill ids and their class names go here
*/
skillStore: {
0: 'playa.modules.monster.MonsterSkill',
1: 'MonsterSkillAttack'
}
};
var specificskill = MonsterSkills.get('1');
console.log(specificskill);
specificskill.update();