如何用javascript解包嵌套函数

时间:2014-06-25 09:27:01

标签: javascript angularjs

大家好我的角度控制器上的每个人我都有以下方法:

$scope.scanSuccess = function(result) {
                    alert("We got a barcode\n" +
                            "Result: " + result.text + "\n" +
                            "Format: " + result.format + "\n" +
                            "Cancelled: " + result.cancelled);
                };

$scope.scanSuccessW = function(){
  return $scope.scanSuccess;
}

有没有办法从scanSuccessW开始获取scanSuccess?当我写这样的东西时:

var s = $scope.scanSuccessW;

总是指scanSuccessW(包装器)而不是包装方法;有没有办法在javascript上解包函数?

1 个答案:

答案 0 :(得分:2)

执行该函数,而不是获取对它的引用,因为它返回$scope.scanSuccess函数。

var s = $scope.scanSuccessW();
//                         ^^ use parenthesis to execute it