为什么jsfiddle给我错误“SyntaxError:Unexpected token:”?

时间:2015-12-06 18:20:51

标签: javascript jsfiddle

我正在使用结构化的javascript代码,它在我的计算机上运行正常。但是当我将它添加到jsFiddle时,它会给我以下错误:

SyntaxError: Unexpected token :

我的代码如下所示:

var StentGallery = {
    gallery: null,

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

有谁知道为什么这不适用于jsFiddle?
在这里看到我的小提琴:https://jsfiddle.net/smyhbckx/

2 个答案:

答案 0 :(得分:5)

您的代码中存在语法错误:

var StentGallery = {
    gallery: null,

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

    resizeImage: function(){
    ...

要解决此问题,只需删除该括号:

var StentGallery = {
    gallery: null,

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

    resizeImage: function(){
    ...

答案 1 :(得分:3)

你的init函数有一个额外的关闭'}'。

相关问题