You are here: All articles » Programming » Solving hard to find "XYZ is not a constructor" JavaScript errors in Magento
-
Solving hard to find "XYZ is not a constructor" JavaScript errors in Magento
written: 10 years ago category: Programming Previous Next
It took me quite a few hours to find the cause of various mysterious errors in Magento's compiled JavaScript files. On most pages these errors did not occur, only on a specific product review page. Magento was told to leave some .js files away on this url. So there was a difference between the compiled .js file on that review url and the other urls. The thing which drived me nuts was: how can I have an error in JavaScript code which just has less code than some other file which was even bigger, but had no error?
Take a look at the following two snippets. The first one does not throw an error:
Product.Config.prototype = { // some code } Calendar = function() { // some code }; (function(global){ // some code })(window);
Now, I'll remove the "Calendar" definition, and suddenly the code throws errors:
Product.Config.prototype = { // some code } (function(global){ // some code })(window);
The reason is a silly missing semicolon after the definition of "Product.Config.prototype". This is only a problem if the immediately following code starts with a parenthesis, like in the second snippet.
In Magento versions up to the newest v1.9 you will find such prototype definitions without a semicolon in the folder /js/varien/. Adding a semicolon at the end of these saved me from getting even more grey hair than I already have.
Leave a comment