Node.js 我可以使用保留关键字吗;在;用咖啡脚本?

Node.js 我可以使用保留关键字吗;在;用咖啡脚本?,node.js,coffeescript,socket.io,Node.js,Coffeescript,Socket.io,我正在尝试将coffeescript与socket.io一起使用 io = socketio.listen(server); // handle incoming connections from clients io.sockets.on('connection', function(socket) { // once a client has connected, we expect to get a ping from them saying what room they want

我正在尝试将coffeescriptsocket.io一起使用

io = socketio.listen(server);
// handle incoming connections from clients
io.sockets.on('connection', function(socket) {
    // once a client has connected, we expect to get a ping from them saying what room they want to join
    socket.on('room', function(room) {
        socket.join(room);
    });
});

// now, it's easy to send a message to just the clients in a given room
room = "abc123";
io.sockets.in(room).emit('message', 'what is going on, party people?');

// this message will NOT go to the client defined above
io.sockets.in('foobar').emit('message', 'anyone in this room yet?'); 
无法正确编译
中的io.sockets.in


我应该如何解决这个问题?

在你的问题中,你说有编译器错误,但在评论中你说没有。如果有,你真的应该发布你的咖啡脚本代码:)

我假设你在《咖啡脚本》中有这样的东西:

io = socketio.listen server

io.sockets.on 'connection', ->
    socket.on 'room', ->
        socket.join room

room = "abc123"
io.sockets.in(room).emit "message", "foobar"

io.sockets.in("foobar").emit "message", "barbaz"
编译成

io = socketio.listen(server);

io.sockets.on('connection', function() {
  return socket.on('room', function() {
    return socket.join(room);
  });
});

room = "abc123";

io.sockets["in"](room).emit("message", "foobar");

io.sockets["in"]("foobar").emit("message", "barbaz");
正如注释中所述,以下两行在JavaScript中是等效的:

io.sockets["in"](room).emit("message", "foobar");
io.sockets.in(room).emit("message", "foobar); 
您可以通过打开您喜爱的JavaScript控制台来验证这一点:

> var test = { foo: "bar" }
> test.foo
'bar'
> test["foo"]
'bar'

编译错误消息是什么?没有错误。但是coffeescript会将io.sockets.in(“foobar”)编译成io.sockets[“in”(“foobar”)。@orionchange这很好。这两个符号在JavaScript中是等价的。这实际上是一个Coffee特性