Ne gubite dragocjeno vrijeme... ... budite uvijek ispred drugih... ... pronađite rješenje stvoreno samo za Vas... ... i ostvarite još jedan korak prema uspjehu. Mi smo tu da Vam u tome pomognemo.
« Nazad

JavaScript quick fix

Although statistics shows that in past few years Internet Explorer is getting less and less used, many business applications are run mainly or even exclusively in Internet Explorer. Unlike other browsers, there is a strong tendency to retain use of old versions like IE7 and IE8 (2,8%). Debugging application in IE can be very painful job especially when other browsers like Mozilla Firefox and Google Chrome don’t reproduce those errors. Here are a few tips to avoid frequent causes of IE errors:

1. Create regex /((\,\s*[\}\)\]\,])|((\;|\,)\s*(\,|\;)))/g

Note: To explain previously mentioned regex use http://regex101.com/ site.

This regex looks for some common JavaScript mistakes and misplaced syntax like comma appears before opened parentheses ( “,)” ), square brackets (“,]” ), curly brackets (“,}”  ), before semicolon (“,;” ), two commas ( “,,” )  and all combination of comma and semicolon appearance.

2. Search whole JavaScript code with ((\,\s*[\}\)\]\,])|((\;|\,)\s*(\,|\;))) regex using for example Eclipse development environment: 

3. After search has been finished examine the search results:

Where these regex can help?

  • In complex structures like in DataTable initialization with:
 

$('#table_id').dataTable({

    "bJQueryUI" : true,

    "bInfo" : true,

    "bDestroy":true,

    "bRetrieve":true,

    "aaSorting": [[1, 'asc']],

    "sDom" : '<"H"Tf>t<"F"lip>',

    "oTableTools": {

       "aButtons": [ "copy", "print",{

                "sExtends":    "collection", "sButtonText": "Save", "aButtons":    [ "csv", "xls", "pdf" ]

       }]

    },

   "aoColumnDefs" : [ { "bSortable" : false, "aTargets" : [ 4 ],  } ]

});

  • Misplaced comma between array elements:

var someArray = [1,2,,3]; 

  • Misplaced comma in function call:

callThisFunction( arg0, arg1, arg2,,argN));

 

Important: This regex search will match regex used in code so you need to examine search result to eliminate regexes that match because they are not errors.

4. Site http://regex101.com/ can also be used to check your code:

 
 
 

This process won’t solve all your JavaScript errors but it will help you to eliminate some of errors that are hard to see and can be a good starting point in debugging your code.