-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjsbase.js
More file actions
91 lines (81 loc) · 1.65 KB
/
Copy pathjsbase.js
File metadata and controls
91 lines (81 loc) · 1.65 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
84
85
86
87
88
89
90
91
/**
*
* Usage:
* var JsBase = require(JsBase.js)
*
*/
var JsBase = {};
JsBase.InsertSortDescend = function (arr) {
if (!(arr instanceof Array)) {
console.error("Error argument, argument type is " + typeof arr + ", require Array");
return void 0;
}
var cloneArr = JsBase.Clone(arr);
for (var i = 1; i < JsBase.SizeOf(cloneArr); i++) {
var key = cloneArr[i];
var j = i - 1;
while (j >= 0 && cloneArr[j] < key) {
cloneArr[j + 1] = cloneArr[j];
j--;
}
cloneArr[j + 1] = key;
}
return cloneArr;
}
JsBase.SizeOf = function (obj) {
var count = void 0;
if (obj instanceof Array) {
count = obj.length;
} else if (typeof obj == "object") {
count = 0;
for (var key in obj) {
count++;
}
} else if (typeof obj == "string") {
return obj.length;
}
return count;
}
//Clone obj
JsBase.Clone = function (obj) {
var o;
if (typeof obj == "object") {
if (obj === null) {
o = null;
} else {
if (obj instanceof Array) {
o = [];
for (var i = 0, len = obj.length; i < len; i++) {
o.push(JsBase.Clone(obj[i]));
}
} else {
o = {};
for (var j in obj) {
o[j] = JsBase.Clone(obj[j]);
}
}
}
} else {
o = obj;
}
return o;
}
JsBase.GetCurTimestamp = function () {
return (new Date).getTime();
}
//All value except undefined is VALID
JsBase.IsValid = function (value) {
return typeof (value) !== "undefined";
}
JsBase.GenSingletonInst = function (classPt) {
return function(){
if(!classPt.Inst){
var ctorFunc = Function.prototype.bind.apply(classPt, arguments);
classPt.Inst = new ctorFunc();
}
return classPt.Inst;
}
}
if (typeof module !== "undefined") {
module.exports = JsBase;
}