我需要一种方法来使用eval javascript函数(或类似的东西)来执行代码,但是下面的代码出错(为什么?):
...
const mathsignarray = ["+", "-", "x", "÷"];
class Letsdoit extends Component {
constructor(props) {
super(props);
this.state = {
a: 15,
b: 17,
mathsign: mathsignarray[Math.floor(Math.random() * 4)],
}
this.result = eval(this.state.a this.state.mathsign this.state.b);
}
...