0

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

代码是:

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

我想知道返回值是多少require 'connect'

是什么{}意思{createServer}

4

1 回答 1

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}"
于 2013-03-16T16:37:19.447 回答