简体   繁体   English

CoffeeScript输入意外结束

[英]Unexpected end of input in CoffeeScript

I've started a little game in CoffeScript using canvas. 我已经在CoffeScript中使用画布开始了一个小游戏。 My problem is this error: 我的问题是此错误:

coffee -c -o lib/ src/
/src/interface.coffee:8:48: error: unexpected end of input
    @ctx.clearRect 0, 0, @size[0], @size[1]
                                           ^

I've rewrote it many times but it still don't want to compile. 我已经重写了很多遍,但是它仍然不想编译。 Here is the code: 这是代码:

class Interface:
    constructor : (id) ->
        @canvas = document.getElementById "#{id}"
        @ctx = @canvas.getContext "2d"
        @size = [@canvas.width, @canvas.height]

    clear : () ->
        @ctx.clearRect 0, 0, @size[0], @size[1]

Oh, and can someone tell me what exactly this error means? 哦,有人可以告诉我这个错误的确切含义吗?

Thank you in advance. 先感谢您。

Its the colon after Interface. 接口后的冒号。 An easy way to debug that error for future reference: 调试该错误以供将来参考的简单方法:

Step 1: paste problem code into the 'Try CoffeeScript' part of the coffeescript website to repro the error. 步骤1:将问题代码粘贴到coffeescript网站的“尝试CoffeeScript”部分,以重现该错误。

Step 2: erase or comment-out lines until the error goes away and the code compiles 步骤2:擦除或注释掉行,直到错误消失并且代码编译为止

Step 3: the last line you erased was the error. 步骤3:您删除的最后一行是错误。

Step 4: find the error(s) in that line and fix. 步骤4:找到该行中的错误并修复。

Step 5: repeat as necessary. 步骤5:视需要重复。

This is how I figured out what the problem was. 这就是我找出问题所在的方式。 This process also works well for the 'Unmatched Outdent' error. 此过程还可以很好地解决“无匹配突出”错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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