Googled but did not find appropriate resource to explain the difference between using Revealing Module Pattern and this
keyword.
When using revealing module pattern I can have the below code :
var moduleRevealing = function() {
var talk = function() {
console.log("Talking....");
};
var walk = function() {
console.log("Walking...");
};
return {
talk: talk,
walk: walk
}
};
console.log('Module Pattern Object');
console.log(moduleRevealing());
Now the same thing can be achieved using this
keyword as below:
var module = function() {
var talk = function() {
console.log("Talking....");
};
this.walk = function() {
console.log("Walking...");
};
this.talk = talk;
};
var mod1 = new module();
console.log('Module Object');
console.log(mod1);
How are both different? I can only see one difference and that is the __proto
; The former points to Object
while the later is module
.
In case someone want's to see the code - Fiddle