From fcec704b7b1298f244cb532906a57d81d4acc36f Mon Sep 17 00:00:00 2001 From: dceejay Date: Mon, 12 Jan 2015 19:11:07 +0000 Subject: [PATCH] Reset some changes to sample to be in line with how most of our nodes actually are. --- nodes/99-sample.js.demo | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/nodes/99-sample.js.demo b/nodes/99-sample.js.demo index ed86e0d7b..939cffd00 100644 --- a/nodes/99-sample.js.demo +++ b/nodes/99-sample.js.demo @@ -31,6 +31,8 @@ module.exports = function(RED) { // Store local copies of the node configuration (as defined in the .html) this.topic = n.topic; + + // copy "this" object in case we need it in context of callbacks of other functions. var node = this; // Do whatever you need to do in here - declare callbacks etc @@ -43,16 +45,16 @@ module.exports = function(RED) { // send out the message to the rest of the workspace. // ... this message will get sent at startup so you may not see it in a debug node. - node.send(msg); + this.send(msg); // respond to inputs.... - node.on('input', function (msg) { + this.on('input', function (msg) { node.warn("I saw a payload: "+msg.payload); // in this example just send it straight on... should process it here really node.send(msg); }); - node.on("close", function() { + this.on("close", function() { // Called when the node is shutdown - eg on redeploy. // Allows ports to be closed, connections dropped etc. // eg: node.client.disconnect();