Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2129907

Browse files
committed
Sample Code
Basic code of module design pattern in javascript
1 parent 859a014 commit 2129907

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

‎modules.html

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<html>
2+
3+
<head>
4+
5+
<script>
6+
7+
var Exposer = (function() {
8+
var privateVariable = 10;
9+
var publicVariable = 20;
10+
11+
var privateMethod = function() {
12+
console.log('Inside a private method!');
13+
privateVariable++;
14+
}
15+
16+
var methodToExpose = function() {
17+
console.log('This is a method I want to expose!');
18+
}
19+
20+
var otherMethodIWantToExpose = function() {
21+
privateMethod();
22+
}
23+
24+
var methodWithParamters = function (a,b) {
25+
console.log(a + ' ' + b);
26+
}
27+
28+
return {
29+
first: methodToExpose,
30+
second: otherMethodIWantToExpose,
31+
third: methodWithParamters,
32+
publicVariable
33+
};
34+
})();
35+
36+
Exposer.first(); // Output: This is a method I want to expose!
37+
Exposer.second(); // Output: Inside a private method!
38+
Exposer.methodToExpose; // undefined
39+
Exposer.third("Hello", "World"); // Method accepting paramters
40+
console.log(Exposer.publicVariable); // Printing public variable
41+
42+
</script>
43+
</head>
44+
45+
<body>
46+
</body>
47+
</html>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /