I'm learning how to create my own node-red node by following the tutorial Creating your first node. If you take a look below, you can see that this
is saved in the variable node
so that you can send a message when an 'input' event is received. That's fine, but why continue using this
to register the 'input' event?
module.exports = function(RED) {
function LowerCaseNode(config) {
RED.nodes.createNode(this,config);
var node = this;
this.on('input', function(msg) {
msg.payload = msg.payload.toLowerCase();
node.send(msg);
});
}
RED.nodes.registerType("lower-case",LowerCaseNode);
}
Couldn't we replace this.on('input', function(msg)
with node.on('input', function(msg)
?