Ortund
Ortund

Reputation: 8245

JQuery plugin options assignment syntax

I'm trying to add options to my first ever jquery plugin, but I keep getting the following error:

Uncaught SyntaxError: Unexpected token : weather2.js:6

My plugin code looks something like this:

(function($) {
    $.fn.extend({
        weather: function(options) {
            var defaults = {
                cityName : "Johannesburg"; // required
                mainImage : ""; // required
                jhbImage : ""; // required
                dbnImage : ""; // required
                cptImage : ""; // required
            };
            var options = $.extend(defaults, options);

            return this.each(function() {
                // plugin logic goes here.
                // options are referenced with options.optionName (eg. options.cityName)
            });
        }
    });
})(jQuery)

The error makes me feel like I should be substituting the colon in the assignments with an equal to same way as var defaults is declared, but every tutorial I've seen suggests that this, too, would be incorrect.

Can anyone provide some clarity?

Upvotes: 0

Views: 221

Answers (2)

murnax
murnax

Reputation: 1222

use commas instead of semicolon in defaults variable.

Upvotes: 0

Mikael Härsjö
Mikael Härsjö

Reputation: 1036

Switch your semicolons for commas in your object literal :)

        var defaults = {
            cityName: "Johannesburg",
            mainImage: "",
            jhbImage: "",
            dbnImage: "",
            cptImage: ""
        };

Upvotes: 1

Related Questions