Permalink
Browse files

1、简化Calculator.__calculate方法

2、增加计算器最大输入长度参数
  • Loading branch information...
1 parent dc351a0 commit 64229f3f8066170a2439286a8dee5dc1be3b7533 @oxcow committed Mar 28, 2012
Showing with 7 additions and 7 deletions.
  1. +7 −7 js/Calculator.js
View
@@ -61,6 +61,9 @@ function bindClickEventToOperPanlBtns() {
}
var Calculator = {
+ options : {
+ MAX_INPUT_LEN : 17,// 最大输入长度
+ },
__x : [],
__oper : null,
__data : [],
@@ -118,14 +121,11 @@ var Calculator = {
},
__calculate : function(evals, x, oper, y) {
- if (evals) {
- console.log(evals);
- return String(eval(evals)).split("");
- } else {
- var res = eval("(" + x + ")" + oper + "(" + y + ")");
- console.log("(" + x + ")" + oper + "(" + y + ")", "=" + res);
- return String(res).split("");
+ if (!evals) {
+ evals = "(" + x + ")" + oper + "(" + y + ")";
}
+ console.log(evals, "= " + eval(evals));
+ return String(eval(evals)).split("");
},
// 一元运算
unaryOperation : function(x) {

0 comments on commit 64229f3

Please sign in to comment.