Skip to content

Commit 700e283

Browse files
committed
Added revealing pattern and some tricky questions
1 parent df999f0 commit 700e283

6 files changed

Lines changed: 73 additions & 48 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.DS_Store

Revealing-pattern.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
var myRevealingModule = (function () {
2+
3+
var privateCounter = 0;
4+
5+
function privateFunction() {
6+
privateCounter++;
7+
}
8+
9+
function publicFunction() {
10+
publicIncrement();
11+
}
12+
13+
function publicIncrement() {
14+
privateFunction();
15+
}
16+
17+
function publicGetCount(){
18+
return privateCounter;
19+
}
20+
21+
// Reveal public pointers to
22+
// private functions and properties
23+
24+
return {
25+
start: publicFunction,
26+
increment: publicIncrement,
27+
count: publicGetCount
28+
};
29+
30+
})();
31+
32+
myRevealingModule.start();

Tricky-Question.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* What would be the OUTPUT of the below code.
3+
*/
4+
5+
(function(){
6+
7+
var MyNameSpace = {
8+
name : "Your Name",
9+
myName : this.name,
10+
display : function(){
11+
console.log(this.myName);
12+
}
13+
}
14+
15+
return MyNameSpace.display();
16+
17+
}).call();
18+
19+
/*
20+
* What below code is doing ?
21+
*/
22+
23+
function library(module){
24+
25+
$(function(){
26+
if(module.init){
27+
module.init();
28+
}
29+
})
30+
31+
return module;
32+
}
33+
34+
var myLibrary = library(function(){
35+
return {
36+
init : function(){
37+
// Your code goes here
38+
}
39+
}
40+
}());

constructor-pattern.js

100644100755
File mode changed.

creational-pattern.js

Lines changed: 0 additions & 48 deletions
This file was deleted.

module-pattern.js

100644100755
File mode changed.

0 commit comments

Comments
 (0)