# Defining and reuse a "classic" JS function

**URL:** <https://discourse.nodered.org/t/defining-and-reuse-a-classic-js-function/16372>\
**Category:** General\
**Created:** [6 October 2019 07:22 UTC](https://discourse.nodered.org/t/defining-and-reuse-a-classic-js-function/16372 "2019-10-06T07:22:29Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![cflurin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cflurin/32/29_2.png) [@cflurin](https://discourse.nodered.org/u/cflurin)\
**Post date:** [6 October 2019 07:57 UTC](https://discourse.nodered.org/t/defining-and-reuse-a-classic-js-function/16372/8 "2019-10-06T07:57:58Z")

</div>

Have a look here:

> [@Use function multiple times](https://discourse.nodered.org/t/use-function-multiple-times/7280/3):
>
> One approach would be to use the global.set() with the memory module. store your function in a global variable: global.set('sum', function(a, b) { return a + b; }, 'memoryOnly'); use your function: msg.payload = global.get('sum', 'memoryOnly')(2, 3); return msg; Note: you need this setting in the settings.js: contextStorage: { default: { module:"localfilesystem" }, memoryOnly: { module: "memory" } }, Flow: [{"id":"4ac…

---

_[View the full topic](https://discourse.nodered.org/t/defining-and-reuse-a-classic-js-function/16372)._
