【发布时间】:2021-10-18 14:18:56
【问题描述】:
我正在使用这种方法来解决这个问题,但我的 console.log 仍然没有返回预期的结果,我应该改变什么?
const executeCalculator = ({ x, y, operation }) => {
let calculator = {
x: this.x,
y: this.y,
operation: {
"sum": (x, y) => x + y,
"subtract": (x, y) => x - y,
"multiply": (x, y) => x * y,
"divide": (x, y) => x / y,
},
}
if (operation !== 'sum' || 'multiply' || 'subtract' || 'divide') {
console.error('undefined operation');
} else {
return;
};
};
console.log(executeCalculator({
operation: 'sum',
x: 1,
y: 1
}));
【问题讨论】:
-
executeCalculator不返回任何内容。 -
您希望它记录什么,而它记录的是什么?
-
另外,
x: this.x不会做任何事情。您解构的值不在this。 -
@mplungjan,您对工作语法的建议缺少
!,否则与他们试图实现的目标相反
标签: javascript function oop