An interesting way to share private state across components of modules in JavaScript:
(credit goes to this article)
12345678910111213141516
varmodule=(function(module){var_private=module._private=module._private||{};var_seal=module._seal=module._seal||function(){deletemodule._private;deletemodule._seal;deletemodule._unseal;}var_unseal=module._unseal=module._unseal||function(){module._private=_private;module._seal=_seal;module._unseal=_unseal;};// permanent access to _private, _seal, and _unsealreturnmodule;}(module||{}));
_unseal must be called by a function (probably some sort of loader function) that was initialized before _seal was called (so that _unseal will be present in its closure scope).