Just note that this method only works with the default in-memory context store, if you ever change default stores, it will fail. There is also no guarantee that even the in-memory store will work this way in the future. The reason is that you cannot easily serialise a JavaScript function. The in-memory store currently doesn't need to serialise but all other stores do.
The only place you can totally rely on this working is by putting the function into settings.js either directly or by requiring it as a module from an external file.