MeteorJS和Coffeescript:“出乎意料.".

MeteorJS and Coffeescript: "unexpected . "

本文关键字:出乎意料 quot Coffeescript MeteorJS      更新时间:2023-09-26

我正在尝试使用 Meteor 电子邮件捆绑包中的 Email.send() 功能,但我遇到了一个小障碍。我正在尝试运行这个:

Email.send
({
    from: 'hello@email.net',
    to: 'someone@somewhere.info',
    subject: 'myapp: wowowowo!',
    text: 'Hello!'
})

流星返回此错误:

=> Started proxy.                             
=> Errors prevented startup:                  
   While building the application:
   <runJavaScript-31>:148:11: server/server.coffee:162: unexpected .
   (compiling server/server.coffee) (at handler)
=> Your application has errors. Waiting for file change.
=> Started MongoDB.  

第 162 行是上述对 send 函数的调用。是的,我已经跑meteor add email了.我该怎么办?我需要一双新鲜的眼睛,谢谢!

使用 js2coffee.org,您可能想尝试一下:

Email.send
  from: "hello@email.net"
  to: "someone@somewhere.info"
  subject: "myapp: wowowowo!"
  text: "Hello!"

尝试将代码插入 http://js2coffee.org/,您将看到它生成的JavaScript。

你可以这样写

Email.send
  from: 'hello@email.net',
  to: 'someone@somewhere.info',
  subject: 'myapp: wowowowo!',
  text: 'Hello!'

但我更喜欢这个:

Email.send(
  from: 'hello@email.net',
  to: 'someone@somewhere.info',
  subject: 'myapp: wowowowo!',
  text: 'Hello!'
)

或者这个:

Email.send({
  from: 'hello@email.net',
  to: 'someone@somewhere.info',
  subject: 'myapp: wowowowo!',
  text: 'Hello!'
})

更清楚的是,它是一个将对象作为参数的函数。

顺便说一句,每次您不确定CoffeeScript代码的作用时,请使用 http://js2coffee.org/来找出它。

事实证明,我的另一个团队成员正在编辑文件,他的文本编辑器插入了制表符而不是空格!我将所有缩进转换为空格分隔,然后它起作用了。