Created
November 25, 2019 23:04
-
-
Save adeelibr/05ad4d63bff2d470bb1347ae41bb831f to your computer and use it in GitHub Desktop.
Closure video example youtube
This file contains 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
// 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