Skip to content

Instantly share code, notes, and snippets.

@iskenxan
Created May 18, 2019 23:30
Show Gist options
  • Select an option

  • Save iskenxan/142628c5698f415e58431bbc68aae7e1 to your computer and use it in GitHub Desktop.

Select an option

Save iskenxan/142628c5698f415e58431bbc68aae7e1 to your computer and use it in GitHub Desktop.
function Hedgehog () {
let speed = 10000; // this is private
this.name = 'Sonic';
this.zoom = function () {
// both name and speed are accessible from here
console.log(`${this.name} zooms with the speed of ${speed} miles per second!`);
}
}
const sonic = new 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