Skip to content

Instantly share code, notes, and snippets.

@justinbmeyer
Forked from matthewp/weakmap.js
Last active August 29, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justinbmeyer/10408375 to your computer and use it in GitHub Desktop.
Save justinbmeyer/10408375 to your computer and use it in GitHub Desktop.
(function(privateThings){
function Private() {
this.data = 'is private';
}
Private.prototype.somePrivateFunction = function() {
this.foo = 'bar';
};
function Public() {
privateThings.set(this, new Private());
}
Public.prototype.somePublicFunction = function() {
var myPrivate = privateThings.get(this);
// myPrivate.data === 'is private';
myPrivate.somePrivateFunction.call(this);
};
})(new WeakMap())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment