无法访问匿名函数

Cannot access anonymous function

有两个环境使用第 3 方库 (BrowserPrint.js);

  1. WORKING ENV - JS 和 jQuery 其中 3party 库仅包含在文档的 <head> 部分

    并且在

    中调用了main函数
    $(document).ready(setup_web_print);
    
  2. NOT WORKING ENV - Angular, JS 和 jQuery

    其中第 3 方库包含在组件中:

    import * as $ from 'jquery';
    import * as bp from '../../../content/js/BrowserPrint-1.0.4.js';
    

    并在 ngOnInit() 生命周期挂钩中触发:

    ngOnInit() {
       $(document).ready(function () {
        ... 
       })
    ...
    }
    

    控制台出错

    ReferenceError: finishedFunction is not defined
    at Object.t.getDefaultDevice (BrowserPrint-1.0.4.js:95)
    

所以它似乎无法访问 finishedFunction

var a = n("GET", e("available"));
        a && (finishedFunction = function(e) {
            response = e, response = JSON.parse(response);
            for (var n in response)
                if (response.hasOwnProperty(n) && response[n].constructor === Array) {
                    arr = response[n];
                    for (var i = 0; i < arr.length; ++i) arr[i] = new t.Device(arr[i])
                }
            return void 0 == o ? void r(response) : void r(response[o])
        }, i(void 0, a, finishedFunction, s), a.send())

有人知道如何解决这个问题吗?为什么在第二个环境中不起作用?

真不知道JavaScript是怎么处理这段逗号写的代码的。但我想这就是你想要的,不是吗?

 if(a) {
    var finishedFunction = function(e) {
      if (response = e, "" == response) return void s(null);
      response = JSON.parse(response);
      var n = new t.Device(response);
      s(n)
    };
    i(void 0, a, finishedFunction, o);
    a.send();
 }