无法确定我为什么会得到"意外的令牌}"

时间:2015-07-23 05:31:08

标签: javascript jquery

很抱歉与语法相关的问题,但我已经尝试了我自己可以做的所有调试,并且没有看到任何错误。到目前为止,我的整个JavaScript文件都是

$(function () { // equivalent to $(document).ready(function() { 

    // div that holds the game area
    var snakeBoardHolder = $('#snake-board-holder');
    // make it have the same height as width
    snakeBoardHolder.height(snakeBoardHolder.width());

    // draw canvas for the snake to live on
    // http://raphaeljs.com/reference.html#Raphael
    if (!Raphael.svg) throw new Error("Your browser does not support SVG elements! Game won't work.");
    var snakeBoard = Raphael("snake-board-holder", snakeBoardHolder.width(), snakeBoardHolder.height());

    // make the game area (div) have height always equal to width,
    // and make the Raphel object (canvas) inside it have the same dimensions 
    $(window).resize(function () {
        var w = snakeBoardHolder.width();
        snakeBoardHolder.height(w);
        snakeBoard.setSize(w, w);
    });


    // define snake object
    function Snake ( )
    {


    }

    // define game object
    function Game ( board, blocksVert, blocksHorz ) 
    {
        //      board: Raphael object that the snake will live on
        // blocksVert: height of the game in blocks
        // blocksHorz: width of the game in blocks 

        var board = this.board;
        var snake; // Snake object on the board
        var openCoords; // coordinates on which the snake is not living at the moment

        function startNew ( ) 
        {
            this.snake = new Snake ();
            this.openCoords = new Array ();
        }
    }

    // start new snake game
    var SG = new Game(snakeBoard, 16, 16);
    SG.startNew();

});

我的Google Chrome控制台告诉我

Uncaught SyntaxError: Unexpected token }

并指向

function startNew ( ) 

如果事实证明是非常明显的话,我道歉。

1 个答案:

答案 0 :(得分:1)

请勿在{{1​​}}中定义您的javascript函数,将其保留在$(function(){...});之外,但在$(function(){...});标记内。

<script>
相关问题