Uncaught SyntaxError:意外的标识符-Chrome VM中的错误 [英] Uncaught SyntaxError: Unexpected identifier - error in Chrome VM

查看:116
本文介绍了Uncaught SyntaxError:意外的标识符-Chrome VM中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常简单的代码,它可以工作,但是它在Chrome的VM3197:1中返回"Uncaught SyntaxError:意外的标识符" 我应该怎么做才能摆脱它?代码对我来说似乎还可以.我正在运行的唯一其他代码是jQuery和html5样板代码片段,以摆脱不支持它的浏览器中的控制台错误.

I have this pretty simple code, which works but it is returning an "Uncaught SyntaxError: Unexpected identifier" in Chrome's VM3197:1 What should I do to get rid of it? Code seems ok to me... The only other code I'm running is jQuery and the html5 boilerplate snippet to get rid of console errors in browser who don't support it.

jQuery(document).ready(function($) {

    var app = (function () {

        var toggleMenu = function(){
            var $offcanvasMenu = $('.offcanvas');
            $offcanvasMenu.toggleClass('-display');
            setTimeout($offcanvasMenu.toggleClass('-show'), 1000);
        };

        return {
            toggleMenu : toggleMenu
        };

    })();

    $('.icon-bars').on('click', function() {
        app.toggleMenu();
    });

});

推荐答案

为了摆脱意外的错误,请尝试更正您的代码的结构.

In order to get rid of unexpected errors, try to correct Your code's structure.

setTimeout期望第一个参数是一个函数,因此您需要在此处使用匿名函数:

setTimeout expects the first parameter to be a function, so You need an anonymous function here:

setTimeout( function(){
    $offcanvasMenu.toggleClass('-show');
}, 1000);

这篇关于Uncaught SyntaxError:意外的标识符-Chrome VM中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆