11.简易计算器methods核心业务代码
eval("this.result=parseFloat(this.n1)${this.opt}parseFloat(this.n2)")
要么就用switch
switch(this.opt){ case "+": this.result=parseFloat(this.n1)+parseFloat(this.n2) break; case "-": this.result=parseFloat(this.n1)-parseFloat(this.n2) break; case "*": this.result=parseFloat(this.n1)*parseFloat(this.n2) break; case "/": this.result=parseFloat(this.n1)/parseFloat(this.n2) break; }