3 ms·
>> There's no theoretical reason a global function can't operate on or return objects. That's not the same thing as stateful at all. "function add(a, b) { retu
by moron4hire 12y ago
>> There's no theoretical reason a global function can't operate on or return objects.
That's not the same thing as stateful at all. "function add(a, b) { return a + b; }" operates on two objects and returns an object, but it maintains no state. I said global state was a bad thing, not global functionality. I added a caveat that global functionality should at least be namespaced, though.
You avoid passing state around by either injecting the dependencies or returning the state transitions to some other thing that makes the state changes happen. You make explicit the relationships that the singletons hide.