Skip to main content
2 votes

Are there any functional approaches, to have variables that feel global (no need to pass them around explicitly), yet are local to an instance?

You are correct in that lots of languages, even OOP languages use tricks like this. eg HttpContext.Current in net framework. You need to access a context for the current operation, but rarely, so you ...
Ewan's user avatar
  • 84.6k
2 votes

Are there any functional approaches, to have variables that feel global (no need to pass them around explicitly), yet are local to an instance?

As the experts in this community pointed out in the comment, the solution is obvious: use OOP, enclose the state in objects and live a happy life: // myLibrary/index.ts import {F} from './f'; export ...
Blue Nebula's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible