4 ms·
Ancient vanilla JS can accomplish similar by using wrapper functions. var React = (function(){ var React = {}; var __SECRET_INTERNALS_DO_NO
by MaulingMonkey 5y ago
Ancient vanilla JS can accomplish similar by using wrapper functions.
var React = (function(){
var React = {};
var __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED = {};
...code extending/using React etc...
return React;
})();
// accessible: React.whatever
// inaccessible: __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
However, there's always caveats where language level access controls don't let you quite express the access restriction you want. Perhaps you want to expose something to other official modules from the same constillation of libraries, for example (meaning you wouldn't be able to use Go's "internal"), without comitting to supporting the semver contract for any other arbitrary user of your API (meaning you might resort to similarly scary names.)
- ______-_-______ 5y agoiirc, react-dom (a separate package) needs to access that property as well, which is why it's exposed in the first place
- udbhavs 5y agoPrivate properties in JS classes are syntactic sugar that compile to variable definitions like this in the object's scope