Javascript回调函数无法使用包含的js文件

时间:2016-10-24 22:04:59

标签: javascript jquery function callback

回调功能在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(...)

0 个答案:

没有答案