Defining and reuse a "classic" JS function

Works well !
I've done a mix with a subflow. :slight_smile:
My subflow, called "JS classic function", has an Inject node "trigger-on-start" and 2 functions (hex2bin and hex2dec) wired to it, so it's executed at 0.1s after Node-Red start and the functions are in memory.
I just had tyo had my Subflow to the flow to enable the classic JS functions.

image
image

Here's the code, if somebody is trying to do the same. :slight_smile:

[{"id":"f9586397.5973","type":"subflow","name":"JS functions","info":"","category":"","in":[],"out":[],"env":[],"color":"#DDAA99"},{"id":"7d7eee51.7878a8","type":"function","z":"f9586397.5973","name":"hex2dec","func":"global.set('hex2dec', function(hexa) {\n    return parseInt(hexa, 16);\n}, 'memoryOnly');\n","outputs":1,"noerr":0,"x":400,"y":80,"wires":[[]]},{"id":"2012dbe6.92df34","type":"function","z":"f9586397.5973","name":"hex2bin","func":"global.set('hex2bin', function(hex) {\n    return (\"00000000\" + (parseInt(hex, 16)).toString(2)).substr(-8);\n}, 'memoryOnly');","outputs":1,"noerr":0,"x":400,"y":40,"wires":[[]]},{"id":"df964a73.694328","type":"inject","z":"f9586397.5973","name":"Trigger on start","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":140,"y":40,"wires":[["2012dbe6.92df34","7d7eee51.7878a8"]]},{"id":"35ca0b72.bb35ec","type":"tab","label":"Test functions","disabled":false,"info":""},{"id":"92ec9209.762ac","type":"inject","z":"35ca0b72.bb35ec","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":120,"wires":[["3c377357.2eb52c"]]},{"id":"3c377357.2eb52c","type":"function","z":"35ca0b72.bb35ec","name":"Test 2 functions","func":"msg.payload = {\n    bin: global.get('hex2bin', 'memoryOnly')(\"0x777\"), \n    dec: global.get('hex2dec', 'memoryOnly')(\"0x777\") \n}\nreturn msg;","outputs":1,"noerr":0,"x":340,"y":120,"wires":[["867de411.01ff3"]]},{"id":"ce6ea1e.e1e90e","type":"subflow:f9586397.5973","z":"35ca0b72.bb35ec","name":"JS Classic functions","env":[],"x":170,"y":60,"wires":[]},{"id":"867de411.01ff3","type":"debug","z":"35ca0b72.bb35ec","name":"Full msg","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":520,"y":120,"wires":[]}]