在此文件中:https://github.com/josh/nack/blob/master/src/server.coffee
代码是:
{createServer} = require 'connect'
{createPool} = require './pool'
我想知道require 'connect'
以及{}
{createServer}
的含义
答案 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}"