Last active
September 17, 2020 04:06
-
-
Save night-fury-rider/ffceaab04b16bab1c36fce3837a3cbed to your computer and use it in GitHub Desktop.
Design Pattern - Enhanced Module
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
var Person = function(personName) { | |
var age = 30; // age will not be accessible outside of Person block | |
var name = 'Yuvraj'; | |
function getName() { | |
return name; | |
} | |
// This return code block is more clean than that of module pattern | |
return { | |
getName: getName | |
} | |
}; | |
var person1 = new Person() | |
console.log(person1.getName()); // Yuvraj | |
console.log(person1.age); // undefined |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment