【发布时间】:2017-01-11 18:37:16
【问题描述】:
这个问题很简单。
这是模块导出函数的方式。
exports = module.exports = debug.debug = debug;
这是 ES5 模块如何使用它的。
var debug = require('debug')('http')
现在在 Typescript 中有点不同了。
import * as debug from 'debug';
这会返回一个我以前从未见过的奇怪对象,一个没有键值对的嵌套对象。
{ [Function: debug]
coerce: [Function: coerce],
disable: [Function: disable],
// More properties go here
}
如何调用函数debug
【问题讨论】:
-
您看到的第一项表明返回的对象是可调用的。您可以调用它,例如
import * as debug from 'debug'; debug('http');. -
不,没有用。
-
??在您的回答中,您调用
debug的方式与我在评论中提到的完全相同。 -
是的,完全一样。
标签: javascript typescript es6-modules