what is the difference between this exporting function in typescript
export const handler = someWrapper(
eventHandler({
...someMiddlewares,
lambdaHandler
})
)
and this exporting in javascript:
module.export ={
someWrapper(
eventHandler({
...someMiddlewares,
lambdaHandler
}),
)
lambdaHandler
}
Please see Difference between “module.exports” and “exports” in the CommonJs Module System
module
is a plain JavaScript object with anexports
property.exports
is a plain JavaScript variable that happens to be set tomodule.exports
. At the end of your file, node.js will basically 'return'module.exports
to > therequire
function. A simplified way to view a JS file in Node could be this:var module = { exports: {} }; var exports = module.exports; // your code return module.exports;
If you set a property on
exports
, likeexports.a = 9;
, that will setmodule.exports.a
as well because objects are passed around as references in JavaScript, which means that if you set multiple variables to the same object, they are all the same object; so thenexports
andmodule.exports
are the same object.
But if you setexports
to something new, it will no longer be set tomodule.exports
, soexports
andmodule.exports
are no longer the same object.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.