咖啡脚本意外换行符

Coffeescript Unexpected Newline

本文关键字:换行符 意外 脚本 咖啡      更新时间:2023-09-26
#Sprite Objects
  sprites =
    1:
      name: "Truffle Faerie"
      location: "sprite.jpg"
      height: "250"
      width: "100"
      placeSprite:()-> 
        elem = document.createElement("img")
        elem.setAttribute("src", spites[1].location)
        elem.setAttribute("height", sprites[1].height)
        elem.setAttribute("width", sprites[1].width)
        document.getElementById("viewport").appendChild(elem)

为什么以上帝的名义在我尝试编译它时给我一个"意外的换行错误"?我不允许在对象方法上使用单独的行吗?

这是我第一次用这种语言打嗝,这足以让我想扯掉我的头发。我只是在这里错过了一些小东西吗?

记事本++是我的文本编辑器。考拉是我的编译器。

好的,

所以经过几个小时,我弄清楚了问题所在。对于其他有此问题的人来说,这是 coffeescript 不能很好地与记事本++一起使用。我的代码是从 Codepen.io 复制到记事本++文件中的,当我去编辑它时,这造成了各种各样的地狱。

我的

解决方法是下载我的代码笔的zip文件,在记事本++中导入coffeescript文件,然后仅使用空格,绝不使用选项卡!

在那些最不令人满意的事情中,这排名最高。

我想,也许和我一样有点不对劲。

 sprites =
    1: # here should be only 1, not [1:], the [:]is error. my code with same error, i find it for long time, maybe can save other people 's time.
      name: "Truffle Faerie"
      location: "sprite.jpg"
      height: "250"