javascript - 有没有办法在创建 Firebase 云函数的同一文件中调用非云函数?
问题描述
我仍然无法理解这些功能通常是如何工作的。对于该项目,我创建了一个函数,只要调用该函数 URL,该函数就会被调用。之后,被调用的函数也使用了一个效用函数。这个函数被多次使用,所以我只发现在一个单独的函数中创建它们是明智的,尽管每当我在部署后使用这个函数时,我都会收到这个错误。
TypeError: this.isMM is not a function
at exports.addOrder.functions.https.onRequest (/user_code/index.js:130:11)
at cloudFunction (/user_code/node_modules/firebase-functions/lib/providers/https.js:57:9)
at /var/tmp/worker/worker.js:783:7
at /var/tmp/worker/worker.js:766:11
at _combinedTickCallback (internal/process/next_tick.js:73:7)
at process._tickDomainCallback (internal/process/next_tick.js:128:9)
我只有一个文件,index.js
其中放置了所有函数,尽管我不确定为什么isMM()
没有读取上述函数。下面是相关的代码块(为了简单起见,我已经替换了函数的内容。
exports.addOrder = functions.https.onRequest((req, res) => {
var newValue = req.query.my_info;
var anotherValue = req.query.another_info;
var my_info = this.isMM(newValue);
if(my_info){
var another_info = this.isMM(anotherValue);
if(another_info){
doThis();
}
}
});
isMM = (toCheck) => {
if(toCheck === 'someString'){
return true;
}
return false;
}
我希望在 addOrder 中使 isMM 可读,因为这将是我需要为这个项目做的重复发生的事情。
解决方案
只需执行以下操作,不要使用this
.
var my_info = isMM(newValue);
if(my_info){
var another_info = isMM(anotherValue);
if(another_info){
doThis();
}
}
推荐阅读
- php - 不要在不完整的对象上调用析构函数(PHP 7.1 不兼容的更改)
- asp.net-web-api - 尝试访问 IIS 10 中托管的 asp.net 核心应用程序时出现内部服务器错误
- html - 推送 ul li 的每个子级别
- python-3.x - 比较两个目录和删除非重复基名的最快 Python 方法
- azure - Microsoft 监控代理 (MMA) 和 OMS 代理之间的区别
- c# - 如何在 SqlKata 中将多个 WHERE 子句连接在一起?
- c# - System.Text.GetBytes 缩短了我的数据,修复了吗?
- node.js - 在 POST 请求结束之前无法访问最近保存的数据 - node.js
- reactjs - 何时/何地在 React 中设置新状态
- python - 返回 JSON 数组中的最小值