简体   繁体   中英

module.export vs export handler in js and typescript

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 an exports property. exports is a plain JavaScript variable that happens to be set to module.exports . At the end of your file, node.js will basically 'return' module.exports to > the require 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 , like exports.a = 9; , that will set module.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 then exports and module.exports are the same object.
But if you set exports to something new, it will no longer be set to module.exports , so exports and module.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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM