-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtestclass.js
54 lines (48 loc) · 1.47 KB
/
testclass.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
var testclass;
// Open the closure to hide the inner components
(function(){
// Define the constructir
testclass = function(v){
// Save "this" to keep the invoker
var self = this;
self.v = v;
var v_2 = v + "_2";
console.log("Construct", v,v_2);
/*****************************************\
|*********** PUBLIC INSTANCE *************|
\*****************************************/
function public_instace(){
console.log("Public instance",self.v, v_2);
private();
}
// Make this function publicly visible by attaching it to the new instance
self.public = public_instace;
/*****************************************\
|************ PRIVATE INSTANCE ***********|
\*****************************************/
function private_instance(){
console.log("Private instance",self.v, v_2);
}
var private = private_instance;
}
/*****************************************\
|************* PUBLIC STATIC *************|
\*****************************************/
function public_static(){
console.log("Public static");
private_static();
}
// Make this function publicly visible by attaching it to the constructor
testclass.public = public_static;
/*****************************************\
|************* PRIVATE STATIC ************|
\*****************************************/
function private_static(){
console.log("Private static");
}
})();
testclass.public();
var a = new testclass("a");
var b = new testclass("b");
a.public();
b.public();