在CoffeeScript中,“{createServer} = require'connect'”是什么意思?

时间:2013-03-16 13:01:56

标签: coffeescript

在此文件中:https://github.com/josh/nack/blob/master/src/server.coffee

代码是:

{createServer} = require 'connect'
{createPool}   = require './pool'

我想知道require 'connect'

的返回值是多少

以及{}

{createServer}的含义

1 个答案:

答案 0 :(得分:2)

{}是CoffeeScripts解构赋值。

//file connect.js 
...
module.exports = {
   createServer: function(){...},
   someOtherExport: function() {...},
   somethingDifferentAgain: function() {...}
};

然后在您的模块中,您只能导入createServer

{createServer} = require "connect"

或者您可以导入连接模块中定义的所有符号

{createServer,
 someOtherExport,
 SomethingDifferentAgain } = require "connect"

如果你想知道从connect导出什么,你应该简单地迭代它

theModule = require 'connect'
for key, value of theModule
    console.log "#{key}: - #{value}"