Skip to content

Instantly share code, notes, and snippets.

@adeelibr
Created November 25, 2019 23:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adeelibr/05ad4d63bff2d470bb1347ae41bb831f to your computer and use it in GitHub Desktop.
Save adeelibr/05ad4d63bff2d470bb1347ae41bb831f to your computer and use it in GitHub Desktop.
Closure video example youtube
// ignore this line, this is just here
// to clear console, everytime I hit "Run with JS"
console.clear();
// Comment out each example one by one & play with
// it, happy coding :)
// @example NOT* a closure example
// function person() {
// let name = 'adeel';
// function displayName() {
// console.log('Name is ::', name);
// };
// displayName();
// };
// person();
// @example closure basic
// function person() {
// let name = 'adeel';
// function displayName() {
// console.log('Name is !!', name);
// };
// return displayName;
// };
// let me = person()();
// @example object (modular reveal pattern)
// let me = {
// name: 'adeel',
// gender: 'male',
// getName: function () {
// console.log('me ::', this.name);
// },
// getGender: function () {
// console.log('me ::', this.gender);
// },
// }
// console.log(me.getName(), me.getGender());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment