繁体   English   中英

无服务器框架函数中的上下文和 module.exports

[英]Context and module.exports in serverless framework functions

在此处输入图像描述

我开始使用 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,这就是将您的 function 实现映射到 serverless.yml 中的 function 声明的原因

The context object is the AWS Lambda context ( https://docs.aws.amazon.com/lambda/latest/dg/nodejs-context.html ). 如果您仔细查看链接的示例适用于 AWS,则处理程序的签名对于其他云平台将有所不同。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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