简体   繁体   中英

Uncaught SyntaxError: Unexpected identifier - error in Chrome VM

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 expects the first parameter to be a function, so You need an anonymous function here:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM