Skip to content

Instantly share code, notes, and snippets.

@romabelka
Last active August 29, 2015 14:17
Show Gist options
  • Save romabelka/642dd8a68c58c008bbc6 to your computer and use it in GitHub Desktop.
Save romabelka/642dd8a68c58c008bbc6 to your computer and use it in GitHub Desktop.
Private object attributes using ES6 WeakMap
var My = (function() {
var privates = new WeakMap;
return function(a) {
privates.set(this, a);
this.setter = function(a) {
privates.set(this, a)
};
this.getter = function() {
return privates.get(this)
};
}
})()
my = new My(1)
console.log(my.getter());
my.setter(2)
console.log(my.getter());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment