我正在开始使用nodejs和无服务器框架。在一些示例中,我已经看到甚至使用了以下代码(来自https://www.serverless.com/framework/docs/providers/aws/guide/functions/):
// handler.js
module.exports.functionOne = function(event, context, callback) {};
2个问题:
1)module.exports与使功能可用于其他结节的通用节点方法有什么关系吗?
2)他们在这里指的是什么背景?基于http://ryanmorr.com/understanding-scope-and-context-in-javascript/
我看到:
Every function invocation has both a scope and a context associated with it. Fundamentally, scope is function-based while context is object-based. In other words, scope pertains to the variable access of a function when it is invoked and is unique to each invocation. Context is always the value of the this keyword which is a reference to the object that “owns” the currently executing code.
这适用于这里吗?
导出是标准的node.js,这是将函数实现映射到serverless.yml中的函数声明的地方>
上下文对象是AWS Lambda上下文(https://docs.aws.amazon.com/lambda/latest/dg/nodejs-context.html)。如果仔细查看链接的示例是针对AWS的,则处理程序的签名对于其他云平台将有所不同。