-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample.js
More file actions
83 lines (64 loc) · 2 KB
/
Example.js
File metadata and controls
83 lines (64 loc) · 2 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/**
* @author Ivan Andonov
* @email: ivan.andonov[at]gmail[dot]com
*
* @require sjs
* @use sjs.Arrays
**/
(function() {
// PRIVATE STATIC VARS - need too be here if we use them for initializing public vars
var privateStaticVar = 'privateStaticVar';
// "cls" variable is used in "private static methods" to access "public static methods" and "public static vars"
var cls = sjs.create('Example', {
// constructor
initialize : function() {
$log(this + '.initialize args=' + sjs.Arrays.argsToArray(arguments));
$log(this + '.initialize cls=' + cls);
// PRIVATE VARS
// "$this" variable is used in "private methods" to access "public methods" and "public vars"
var $this = this;
var privateVar = 10;
// PUBLIC VARS
this.publicVar = 20;
// PRIVATE METHODS
function privateMethod() {
$log($this + '.privateMethod');
privateVar++;
$this.publicVar++;
return $this.publicMethod1();
};
// PUBLIC METHODS
this.getter = function(v) {
return this[v] != undefined ? this[v] : eval(v);
};
this.publicMethod = function() {
$log(this + '.publicMethod cls=' + cls);
return privateMethod();
};
this.publicMethod1 = function() {
$log(this + '.publicMethod1');
return 'privateVar=' + privateVar + ' publicVar=' + this.publicVar + ' classInstance=' + this.classInstance();
};
},
// PUBLIC STATIC VARS
publicStaticVar : 'publicStaticVar',
// PUBLIC STATIC METHODS
publicStaticMethod : function() {
$log(this + '.publicStaticMethod');
return privateStaticMethod();
},
publicStaticMethod1 : function() {
$log(this + '.publicStaticMethod1');
return privateStaticMethod1();
}
});
// PRIVATE STATIC METHODS
function privateStaticMethod() {
$log(cls + '.privateStaticMethod');
return cls.publicStaticMethod1();
};
function privateStaticMethod1() {
$log(cls + '.privateStaticMethod1');
return cls.publicStaticVar + ' ' + privateStaticVar + ' ' + cls;
};
})();