-
Notifications
You must be signed in to change notification settings - Fork 2
/
testclass2.js
57 lines (49 loc) · 1.49 KB
/
testclass2.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
55
56
57
var testclass = (function(){
var private = new WeakMap();
/*****************************************\
|*********** PUBLIC INSTANCE *************|
\*****************************************/
function public_instance(){
console.log("Public instance",this.v, private.get(this).v_2);
private.get(this).private.apply(this);
}
/*****************************************\
|************ PRIVATE INSTANCE ***********|
\*****************************************/
function private_instance(){
console.log(this);
console.log("Private instance",this.v, private.get(this).v_2);
}
// Define the constructor
function testclass(v){
var privateProps = {
v_2:v + "_2",
private: private_instance
};
this.v = v;
private.set(this, privateProps);
console.log("Construct", this.v,private.get(this).v_2);
}
testclass.prototype.public = public_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");
}
return testclass;
})();
testclass.public();
var a = new testclass("a");
var b = new testclass("b");
a.public();
b.public();