How to pass around global or local state implicitly

In my situation I have functions, some of which will use global state, some of which will use local state like the function scope or parent scope, others which use both.

So for example you might have stuff like this:

var MY_GLOBAL = 10 var GLOBAL_STATE = {}  function myfunction1(a) {   return a + myfunction2(a) }  function myfunction2(a) {   return a * MY_GLOBAL + this.parent.arguments[0] }  function myfunction3(k, v) {   return GLOBAL_STATE[k] = v } 

Say I have a 100 functions which all act on the global state. One thing I can do is pass it to every function:

function afunction(state, ...rest) { ... } 

But I’m not sure I want to do this as it would require removing the simplicity and clarity of the functions. I like the idea of having special global variables which you reference in the code. However, I don’t want to just be referencing random global variables.

So one solution I am sort of imagining is having the function definition include the global variable, only if it directly uses it. Then somehow it gets injected in or something. Then any subfunctions that use the global variable, they also get it injected in rather than passed down.

Basically the end goal is I think to not pollute all the functions with these at least 2 variables (global state, and local scope), yet still be able to use them in any function. Wondering what sorts of solutions exist for this. I tried to check out Haskell’s State Monad, but not being a Haskell programmer I don’t see how it works.

Thinking in terms of functional programming with mutable state, not OO programming. Basically like JavaScript.

Can I prove my legal age *implicitly* so that I can drink in the UK?

I hold Swede passport and I am traveling to UK this month. I’ve read (http://news.bbc.co.uk/2/hi/uk_news/6598867.stm) that legal age of drinking alcohol in UK is 16 to 18 depending on the type of beverage.

I am an undergraduate student and look about 18. Can I use my my university card (Swede uni) in place of my passport in bar entries. Since a typical university student is 18 or above so can my university card be as a proof of age, implicitly though?