回调功能在Console中运行(当我在Console上运行代码但在脚本文件中它无效时
define(['jquery'],function($){
function calc(x,y,aa){
console.log("--",aa,"--");
aa(x,y);
}
function add(x,y){
return parseInt(x+y);
}
function sub(x,y){
return parseInt(x-y);
}
function div(x,y){
return x/y;
}
return calc;
});
and then
$('#calcbutton').click(function(){
var val1 = Number($('#var1').val()),
val2 = Number($('#var2').val()),
opper = $('#opp').val(),
opp = opper.trim(),
result = $('#result'),
num1 = $.trim(val1),
num2 = $.trim(val2);
var aa = calculator(val1,val2,add);
});
如果我从console.log运行它,同样的exaple有效,我收到错误app.js:22 Uncaught ReferenceError:add is not defined(...)