No, a function operates where you design it unless you pass in some context to operate on.
There are a few ways (binding / apply etc) but here are 2 of the simpler ways...
First one - you pass in the node context to operate on...
// function 1
msg.functions={
foo:function(n){
n.send({"desc":"foo"})
},
bar:function(n){
n.send({"desc":"bar"})
}
}
// function 2
msg.functions.foo(node)
msg.functions.bar(node)
Another way is a function factory...
// function 1
msg.functionFactory=function(_node){
var node = _node;
return {
foo:function(){ node.send({"desc":"foo"}) },
bar:function(){ node.send({"desc":"bar"}) }
}
}
// function 2
var ff = new msg.functionFactory(node);
ff.foo()
ff.bar()
demo flow...
[{"id":"3cd6fd57.dbf502","type":"inject","z":"336fad55.d74c02","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":844,"y":544,"wires":[["f740d75f.c6de88"]]},{"id":"f740d75f.c6de88","type":"function","z":"336fad55.d74c02","name":"passing context","func":"msg.functions={\n foo:function(n){\n n.send({\"desc\":\"foo\"})\n },\n bar:function(n){ \n n.send({\"desc\":\"bar\"})\n }\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1014,"y":544,"wires":[["d19ea6d5.e69e48","8deb8124.fb84b"]]},{"id":"513f0336.015a8c","type":"debug","z":"336fad55.d74c02","name":"out 1 :D","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1454,"y":544,"wires":[]},{"id":"d19ea6d5.e69e48","type":"function","z":"336fad55.d74c02","name":"apply func","func":"msg.functions.foo(node)\nmsg.functions.bar(node)\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1244,"y":544,"wires":[["513f0336.015a8c"]]},{"id":"8deb8124.fb84b","type":"debug","z":"336fad55.d74c02","name":"Why im here?","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1254,"y":604,"wires":[]},{"id":"f7bdf46e.066cb8","type":"inject","z":"336fad55.d74c02","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":844,"y":656,"wires":[["2fb421b0.9c836e"]]},{"id":"2fb421b0.9c836e","type":"function","z":"336fad55.d74c02","name":"functionFactory","func":"msg.functionFactory=function(_node){\n var node = _node;\n return {\n foo:function(){ node.send({\"desc\":\"foo\"}) },\n bar:function(){ node.send({\"desc\":\"bar\"}) }\n }\n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1014,"y":656,"wires":[["ceed402d.fb068","dfe7dc7d.9db2e"]]},{"id":"ceed402d.fb068","type":"function","z":"336fad55.d74c02","name":"apply func","func":"var ff = new msg.functionFactory(node);\nff.foo()\nff.bar()","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1244,"y":656,"wires":[["a763a36d.2b0b7"]]},{"id":"dfe7dc7d.9db2e","type":"debug","z":"336fad55.d74c02","name":"Why im here?","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1254,"y":716,"wires":[]},{"id":"a763a36d.2b0b7","type":"debug","z":"336fad55.d74c02","name":"out 1 :D","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1454,"y":656,"wires":[]}]