Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
WeakMap and private
var privateThings = new WeakMap();
function Private() { = 'is private';
Private.prototype.somePrivateFunction = function() { = 'bar';
function Public() {
privateThings.set(this, new Private());
Public.prototype.somePublicFunction = function() {
var myPrivate = privateThings.get(this);
// === 'is private';;

This comment has been minimized.

Copy link

@justinbmeyer justinbmeyer commented Apr 10, 2014

Why couldn't I do:

var p = new Public();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.