Created
May 18, 2019 23:32
-
-
Save iskenxan/1ab5172b812b807a188232ad43e50588 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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