因此,我正在尝试使用 JavaScript“类”来尝试澄清和简化我的一些代码。我所拥有的是这样的:
function action (name, vActor, vTarget) {
this.name = name;
this.vActor = vActor;
this.vTarget = vTarget;
this.addRoll = addRoll;
this.children = {};
}
function addRoll (name, diffMod, dice, success, critSuccess, failure) {
this.children[name] = {} ;
this.children[name].diffMod = diffMod;
this.children[name].dice = dice;
this.children[name].success = {condition: success, outcome: {}};
this.children[name].critSuccess = {condition: critSuccess, outcome: {}};
this.children[name].failure = {condition: failure, outcome: {}};
this.children[name].addSuccess = addSuccess;
this.children[name].addFailure = addFailure;
this.children[name].addOutcome = addOutcome;
}
这是解决这个问题的正确方法吗?我的主要问题是关于谁拥有“function addRoll()”部分中的“this”对象。我假设“这个”仍然属于动作“类”。我也不确定关于开始一个新的空白对象和使用点符号分配东西的语法。提前致谢。