File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed
Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change 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 >
You can’t perform that action at this time.
0 commit comments