mathOp = function(type){
return (
"add" == type? function(a,b){return a + b}
:"mul" == type? function(a,b){return a * b}
:"sub" == type? function(a,b){return a - b}
:"div" == type? function(a,b){return a / b}
)
}
Chrome JS debugger tool says: SyntaxError: Unexpected token )
What is wrong with this syntax ?
You forgot the last
: elsepart.You could make it more readable by using
switch():