我有这门课
class MyClass {
constructor(name, health, damage){
INamable(this)
IHealth(this)
IDamage(this)
IAttack(this)
ITakeDamage(this)
this.setName(name)
this.setHealth(health)
this.setDamage(damage)
}
attack(target){
target.takeDamage(this.getDamage());
}
takeDamage(damage){
this.setHealth(this.getHealth() - damage);
if(this.getHealth()<=0){
this.die();
}
}
toString(){
return "myClassToString"
}
}
Run Code Online (Sandbox Code Playgroud)
// 一些接口(方法)
function IAttack(object){
let attack = function(){}
object.attack = attack;
}
function ITakeDamage(object){
let takeDamage = function(){}
object.takeDamage = takeDamage;
}
Run Code Online (Sandbox Code Playgroud)
我的问题是为什么attack(target)不takeDamage(damage)重写构造函数中继承的方法。我知道以前可能有人问过这个问题,但抱歉我找不到。
这是非常愚蠢的问题,但我不知道它为什么会发生.我在控制器中发现了这个:
this.getView().setModel(this.placesModel, "myCity");
Run Code Online (Sandbox Code Playgroud)
然后我用Ajax请求将数据设置到我的快速RESTFull应用程序和View.xml中
<List items="{path: 'myCity>/people'}">
<CustomListItem>
<VBox>
<Title text="Person:"/>
<Label text="{myCity>/people/name}"/>
<Label text="{myCity>/people/age}"/>
</VBox>
</CustomListItem>
</List>
Run Code Online (Sandbox Code Playgroud)
我有myCity几个属性的对象.其中一个是对象people,它是一组对象.当我尝试列出这些时,我可以看到我的所有人都被列出但没有相应的姓名和年龄.此外,我发现很难>在/何时何时使用>/.