Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

trailing comma problem, javascript

I'm currently trying hard to get my jQuery to work in IE7, when I Lint the following:

$(".regflow").validate({
    errorLabelContainer: $("#error-message"),
    rules: {
        txtTextOnly: {required: true,textOnly: true},
        txtNumbersOnly: {required: true,numbersOnly: true},
        txtPhoneOnly: {required: true,phoneOnly: true},
        txtAreaCodeOnly: {required: true,numbersOnly: true},
        txtSimCodeOnly: {required: true,simCodeOnly: true},
        txtCprOnly1: {required: true,numbersOnly: true},
        txtCprOnly2: {required: true,cprOnly1: true},
        txtMailOnly: {required: true,mailOnly: true}
    },

    messages: {
        txtTextOnly: {required: "Dette felt skal udfyldes"},
        txtNumbersOnly: {required: "Dette felt skal udfyldes"},
        txtPhoneOnly: {required: "Dette felt skal udfyldes"},
        txtAreaCodeOnly: {required: "Dette felt skal udfyldes"},
        txtSimCodeOnly: {required: "Dette felt skal udfyldes"},
        txtCprOnly1: {required: "Dette felt skal udfyldes"},
        txtCprOnly2: {required: "Dette felt skal udfyldes"},
        txtMailOnly: {required: "Dette felt skal udfyldes"}
    },
});

... I get this error from Lint: "warning: trailing comma is not legal in ECMA-262 object initializers"

Does anyone know what this means, and how do I fix it?

like image 476
timkl Avatar asked Nov 30 '09 13:11

timkl


1 Answers

Remove the trailing comma - the comma at the end of the following part:

 messages: {
        txtTextOnly: {required: "Dette felt skal udfyldes"},
        txtNumbersOnly: {required: "Dette felt skal udfyldes"},
        txtPhoneOnly: {required: "Dette felt skal udfyldes"},
        txtAreaCodeOnly: {required: "Dette felt skal udfyldes"},
        txtSimCodeOnly: {required: "Dette felt skal udfyldes"},
        txtCprOnly1: {required: "Dette felt skal udfyldes"},
        txtCprOnly2: {required: "Dette felt skal udfyldes"},
        txtMailOnly: {required: "Dette felt skal udfyldes"}
    },

While creating an object {} or an array [], you separate individual elements with a comma. But here there is an additional comma after the last item like [a, b, c,] - that is not allowed as per ECMA-262.

like image 83
Amarghosh Avatar answered Sep 19 '22 16:09

Amarghosh