javascript - 为什么 jsfiddle 给我错误 "SyntaxError: Unexpected token :"?

标签 javascript jsfiddle

我正在使用结构化的 javascript 代码,它在我的电脑上运行良好。但是当我将它添加到 jsFiddle 时,它​​给了我以下错误:

SyntaxError: Unexpected token :

我的代码是这样的:

var StentGallery = {
    gallery: null,

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

有谁知道为什么这在 jsFiddle 中不起作用?
在这里查看我的 fiddle :https://jsfiddle.net/smyhbckx/

最佳答案

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

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(){
    ...

关于javascript - 为什么 jsfiddle 给我错误 "SyntaxError: Unexpected token :"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34120947/

相关文章:

javascript - 选择 capybara 验收测试

javascript - 如何防止 react 表排序和搜索重置

javascript - d3 如果数据中存在值,则添加文本元素

javascript - Tag-it 不适用于 jsfiddle

jsfiddle js面板大小被卡住了!我该如何重置它?

javascript - div 和 text() 有点奇怪

javascript - 调用函数用正则表达式替换某些子字符串的问题

javascript - div的css过渡效果

html - 为什么我的 "pre"HTML 标记在一个特定实例中不起作用?

javascript - JQuery Slider 帮助 - 鼠标悬停事件解决方案