0

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

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

    and the main function is called in

    $(document).ready(setup_web_print);
    
  2. NOT WORKING ENV - Angular, JS and jQuery

    where 3rd party libraries are included in component:

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

    and triggered in ngOnInit() lifecycle hook:

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

    There is an error in console

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

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?

1 Answer 1

1

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();
 }
Sign up to request clarification or add additional context in comments.

3 Comments

Apparently it'll just evaluate all the arguments then return the last one. developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…
@GPW thank you for that clarification! But as far as I can see he is not even reading the return value. So I would say it could be rewritten like I showed.
Yes, looked reasonable... And on slightly more careful reading It doesn't look like it'd execute the call to finishedFunctionif a evaluated to false, which is what I thought might be wrong. Either way, that code is not particularly readable in that form!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.