Skip to content

Instantly share code, notes, and snippets.

@nrkn
Last active May 27, 2019 23:30
Show Gist options
  • Save nrkn/a40b8be2e7643b307ead054ae70082a9 to your computer and use it in GitHub Desktop.
Save nrkn/a40b8be2e7643b307ead054ae70082a9 to your computer and use it in GitHub Desktop.
Encapsulation with ES6 modules
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!`)
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