Shared functions in HTML

I'm developing a plugin containing multiple custom nodes (with all nodes contained in a single HTML file). At the moment, there is quite a lot of code duplication between the various nodes, for example in their oneditprepare handlers.

What would be the proper way to define JavaScript functions that are shared between the various nodes?

For now, the only way I've been able to make this work is to have something like the following in one of the script blocks for one of the nodes:

<script type="text/javascript">
   RED.myTestFunction = function() {
      console.log("myTestFunction called");

This allows me to call this function from the various handlers using RED.myTestFunction(), but I doubt whether this is a good approach. Are there any better approaches?