我注意到Azure功能似乎没有保留this
的值以用于原型继承。在构造函数原型上定义的方法体内记录this
的值将返回undefined
。只是想知道这是否是Azure功能中的正常和预期行为。我也想知道是否有办法绕过它,因为无法访问原型继承是蹩脚的。
编辑:这里有更多信息。
我导入一个Node模块,它是一个构造函数,并在我的Azure函数中实例化该函数的一个实例(恰好是一个计时器触发器,顺便提一下)。在该模块中,我在其原型上定义了构造函数的方法。问题是Azure似乎不尊重原型继承,并且正在失去对this
的引用,undefined
会返回const Poll = function () {...};
Poll.prototype.getUnprocessedCandidates = function () {...};
Poll.prototype._getUnprocessedCandidates = function () {
let self = this;
self._filterProcessedCandidates();
};
。
编辑2(代码):
poll.js
'use strict';
const Poll = require('./poll');
module.exports = function (context, candidateQueueTimer) {
let poll = new Poll();
poll.pollForCandidates(context)
.then(poll.getUnprocessedCandidates)
.then(() => { context.done(); })
.catch(error => context.done(error));
};
定时器触发
this
^请忽略传递的论据等等。他们根本不承担这个问题。
我应该提到我在Windows中使用Node Azure Functions软件包。 (我实际上是在开发这个应用程序,主要是在Mac上,然后在Windows环境中实际执行这些功能。)当我从"的主体内记录import cpuinfo
print cpuinfo.get_cpu_info()
的值时。公共" getUnprocessedCandidates方法(Poll.prototype.getUnprocessedCandidates),输出似乎是某种Azure函数对象。
答案 0 :(得分:0)
Azure Functions不会阻止原型继承工作。例如,以下工作:
boton1.topAnchor.constraint(equalTo: textfield1.bottomAnchor, constant: 4).isActive = true
boton1.leftAnchor.constraint(equalTo: customAlert.leftAnchor, constant: 2).isActive = true
boton1.rightAnchor.constraint(equalTo: lineaSeparadora2.leftAnchor, constant: -10).isActive = true
boton1.heightAnchor.constraint(equalToConstant: 50).isActive = true
lineaSeparadora2.topAnchor.constraint(equalTo: boton1.topAnchor, constant: 0).isActive = true
lineaSeparadora2.bottomAnchor.constraint(equalTo: boton1.bottomAnchor, constant: 0).isActive = true
lineaSeparadora2.widthAnchor.constraint(equalToConstant: 7).isActive = true
boton2.topAnchor.constraint(equalTo: textfield1.bottomAnchor, constant: 4).isActive = true
boton2.leftAnchor.constraint(equalTo: lineaSeparadora2.rightAnchor, constant: 10).isActive = true
boton2.rightAnchor.constraint(equalTo: customAlert.rightAnchor, constant: -2).isActive = true
boton2.heightAnchor.constraint(equalToConstant: 50).isActive = true
boton1.widthAnchor.constraint(equalTo: boton2.widthAnchor).isActive = true
您是否在不使用bind的情况下切换对方法的引用?