JsBarcode: "Renderer is not a constructor"

This is not a direct issue for us, but to help you improve your code, I thought I’d share something I found. We are getting the Exception “i is not a constructor”. You can safely catch and ignore the exception, and everything seems to work fine, but it is still there.

My code now is the following:

try {
    JsBarcode(imgID, barValue, {format:barFormat, displayValue:showValue, fontSize:parseInt(barFont), width:parseInt(barWidth), height:parseInt(barHeight), ratio:0.8});
} catch (err) {
    jslog("Error when using JsBarcode: " + err.message);
    //There is an error in JsBarcode we need to ignore (ie: i is not a constructor)
}

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 25 (14 by maintainers)

Commits related to this issue

Most upvoted comments

That is absolutely the reason! I know to not loop over array with for in but sometimes you do the simplest thing you know are going to work (on your machine).

I will patch the issue sometime this weekend.

Thanks very much for the assistance!

@lindell I think I know what is causing the problem. I couldn’t get the issue reproduced in a codepen snippet or something, so I started to do some digging myself.

I discovered that the are some places where you iterate over an array using a for loop. That would be a normal thing in plain javascript, however in my case, I am using this library inside an Ember.js project. Ember.js extends the prototype of Array with a lot of extra functions, somehow causing extra keys.

In a plain javascript console, iterating over array keys looks like this:

schermafbeelding 2016-09-02 om 17 16 01

However, in an Ember.js project, it looks like this:

schermafbeelding 2016-09-02 om 17 15 51

Finally, this causes this location in your project to fail:

schermafbeelding 2016-09-02 om 17 15 34

That also explains why the barcode is still rendered (on the first iteration) and why it is rendering more then once (for each key).

Probably the other people that are having this problem are also using a library that manipulates the array prototype. This is probably an example of why prototype extensions are a bad idea haha. However, this could be fixed by using something like this to iterate (in es6):

this._renderProperties.forEach((renderProperties) => {
  render(renderProperties, ...);
});

So, here is a codepen example that does reproduce the issue: http://codepen.io/anon/pen/EgxLBB

Perfect! I released 3.3.23 now. Closing the issue.

@lindell I have just tested your file in my environment and I can confirm that the issue seems to be fixed!

Thank you for your quick response and action!