无法访问匿名函数 [英] Cannot access anonymous function

查看:36
本文介绍了无法访问匿名函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有两种使用第三方库(BrowserPrint.js)的环境;

There are two environments which using the 3rd party library (BrowserPrint.js);

  1. 工作环境 - JS 和 jQuery其中 3party 库仅包含在文档的 部分

  1. WORKING ENV - JS and jQuery where 3party libraries are included simply in the <head> part of the document

并且在

$(document).ready(setup_web_print);

  • 不适用于环境 - Angular、JS 和 jQuery

  • NOT WORKING ENV - Angular, JS and jQuery

    组件中包含第 3 方库的位置:

    where 3rd party libraries are included in component:

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

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

    and triggered in ngOnInit() lifecycle hook:

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

    控制台出现错误

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

  • 所以它似乎无法访问 finishedFunction

    so it seems it cannot access 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())
    

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

    Does anybody know how to fix this and why doesn't work with in second env?

    推荐答案

    我真的不知道 JavaScript 是如何处理这段用逗号编写的代码的.但我认为这就是你想要的,不是吗?

    I really don't know how JavaScript is handling this comma-written code. But I think this is what you want, isn't it?

     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();
     }
    

    这篇关于无法访问匿名函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆