【发布时间】:2018-04-29 11:25:31
【问题描述】:
我正在寻找一种方法来更改方法“answer(x,y)”在 Child 类中的行为方式并交换变量 x 和 y,以便最后一条语句返回“true”。但是,任务是我不能更改 Child 类,只能更改 Parent。
class Parent {
// some code
}
class Child extends Parent {
answer(x, y) {
this.x = x;
this.y = y;
return 75 - this.x + this.y;
}
}
let v = new Child();
v.answer(5, 15) === 65; //should be true
v.answer(15, 5) === 85; //should be true
【问题讨论】:
-
@diceler 恰恰相反。请仔细阅读问题。
标签: javascript class ecmascript-6 es6-class