Last active
May 27, 2019 23:30
-
-
Save nrkn/a40b8be2e7643b307ead054ae70082a9 to your computer and use it in GitHub Desktop.
Encapsulation with ES6 modules
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
export const Hedgehog = () => { | |
const speed = 10000 | |
const name = 'Sonic' | |
const hedgehog = { | |
name, | |
zoom: () => zoom( hedgehog.name, speed ) | |
} | |
return hedgehog | |
} | |
const zoom = ( name, speed ) => | |
console.log(`${ name } zooms with the speed of ${ speed } miles per second!`) |
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
import { Hedgehog } from './hedgehog' | |
const sonic = Hedgehog() | |
sonic.zoom() | |
console.log( sonic.name ) //valid value | |
console.log( sonic.speed ) // undefined |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment