Skip to content

Instantly share code, notes, and snippets.

@iskenxan
Created May 18, 2019 23:32
Show Gist options
  • Save iskenxan/1ab5172b812b807a188232ad43e50588 to your computer and use it in GitHub Desktop.
Save iskenxan/1ab5172b812b807a188232ad43e50588 to your computer and use it in GitHub Desktop.
let Hedgehog = (function () {
let privateProps = new WeakMap();
class Hedgehog {
constructor(name) {
this.name = name; // this is public
privateProps.set(this, { speed: 1000 }); // this is private
}
zoom() {
console.log(`${this.name} zooms with the speed of ${privateProps.get(this).speed} miles per second!`);
}
}
return Hedgehog;
})();
let sonic = new Hedgehog('Sonic');
console.log(sonic.zoom());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment