Javascript 的布尔错误
Boolean mistake with Javascript
有这个代码:
function checkIsNotOverHeating(context, surchauffe, offset, topic, node){
let msg = null;
let overheating;
overheating = false;
if(checkTemperatureWithOffset(context.get("temperatureInt"), offset, surchauffe, "-") === 1){
// Overheating
overheating = true;
msg = createMessageOverheat(topic);
}
node.error(overheating)
if(context.get("overheating") !== overheating) context.set("overheating", overheating);
return msg;
}
每node.error会在Node中输出参数中的值。我不明白为什么,但它会接受布尔值 true,而不是 false,正如您在这张图片中看到的那样:
我正在使用 NodeRED,如您所见,代码很简单。我的功能每次都触发。
编辑:不用管 -1,它只会显示 2 值的变化
这看起来像是 node.error()
代码中的错误,作为变通方法试试这个:
node.error(' ' + overheating);
编辑:
已提交修复:
有这个代码:
function checkIsNotOverHeating(context, surchauffe, offset, topic, node){
let msg = null;
let overheating;
overheating = false;
if(checkTemperatureWithOffset(context.get("temperatureInt"), offset, surchauffe, "-") === 1){
// Overheating
overheating = true;
msg = createMessageOverheat(topic);
}
node.error(overheating)
if(context.get("overheating") !== overheating) context.set("overheating", overheating);
return msg;
}
每node.error会在Node中输出参数中的值。我不明白为什么,但它会接受布尔值 true,而不是 false,正如您在这张图片中看到的那样:
我正在使用 NodeRED,如您所见,代码很简单。我的功能每次都触发。
编辑:不用管 -1,它只会显示 2 值的变化
这看起来像是 node.error()
代码中的错误,作为变通方法试试这个:
node.error(' ' + overheating);
编辑:
已提交修复: