Why does jsfiddle give me the error "SyntaxError: Unexpected token:"?

I am using structured javascript code and it works fine on my computer. But when I add it to jsFiddle, it gives me the following error:

SyntaxError: Unexpected token :

My code is as follows:

var StentGallery = {
    gallery: null,

    init : function(){
            this.gallery = jQuery('#gallery-list-ui');
            this.resizeImage();
        }
    }
    (...)
}

Does anyone know why this is not working in jsFiddle?
See my fiddle here: https://jsfiddle.net/smyhbckx/

+4
source share
2 answers

There is a syntax error in the code:

var StentGallery = {
    gallery: null,

    init : function(){
           this.gallery = jQuery('#gallery-list-ui');
           this.resizeImage();
           } // <----- this is prematurely closing your object
    }, 

    resizeImage: function(){
    ...

To fix this, just remove this bracket:

var StentGallery = {
    gallery: null,

    init : function(){
           this.gallery = jQuery('#gallery-list-ui');
           this.resizeImage();
    },

    resizeImage: function(){
    ...
+5
source

There is an additional closure '}' for your init function.

+3
source

Source: https://habr.com/ru/post/1618803/


All Articles