开发者

CoffeeScript to Node.js Syntax problem of ")"

I have a problem "too many ) on line 开发者_运维百科21" I can't compile this Coffee Script Code into Node.js Any help about these ")" ? Thanks

amqp = require('amqp')

class Queue
    constructor: (ip = 'localhost') ->
            @ip = ip
            @receivedObject
            @connection = amqp.createConnection({ host: @ip })

    subscribeTaskQueue: (queueToSubscribe) ->
            self = @
            self.connection.on('ready', ->
                    q = self.connection.queue(queueToSubscribe)
                    q.bind('#')

                    q.subscribe({ ack: true }, (message) ->
                            self.receivedObject = message
                            console.log(self.receivedObject)
                    )
            )

    addTaskToQueue: (queue, objectToSend) ->
            @connection.publish(queue, objectToSend)

module.exports = Queue


This is one area in which CoffeeScript rocks: you can omit the parens when calling functions with arguments! This is especially nice in Node, where the callback is usually the last argument.

Like this:

amqp = require 'amqp'

class Queue

   constructor: (ip = 'localhost') ->
        @ip = ip
        @receivedObject
        @connection = amqp.createConnection { host: @ip } 

   subscribeTaskQueue: (queueToSubscribe) ->
        self = @
        self.connection.on 'ready', ->
                q = self.connection.queue queueToSubscribe
                q.bind '#'

                q.subscribe { ack: true }, (message) ->
                        self.receivedObject = message
                        console.log(self.receivedObject)

   addTaskToQueue: (queue, objectToSend) ->
        @connection.publish queue, objectToSend

module.exports = Queue 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜