-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy path11230.js
71 lines (69 loc) · 1.62 KB
/
11230.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
-function() {
function Overload(fn_objs) {
var is_match = function (x, y) {
if (x == y) return !0;
if (x.indexOf("*") == -1) return !1;
var x_arr = x.split(","),
y_arr = y.split(",");
if (x_arr.length != y_arr.length) return !1;
while (x_arr.length) {
var x_first = x_arr.shift(),
y_first = y_arr.shift();
if (x_first != "*" && x_first != y_first) return !1;
}
return !0;
};
var ret = function () {
var args = arguments,
args_len = args.length,
args_types = [],
args_type,
fn_objs = args.callee._fn_objs,
match_fn = function () {};
for (var i = 0; i < args_len; i++) {
var type = typeof args[i];
type == "object" && (args[i].length > -1) && (type = "array");
args_types.push(type);
}
args_type = args_types.join(",");
for (var k in fn_objs) {
if (is_match(k, args_type)) {
match_fn = fn_objs[k];
break;
}
}
return match_fn.apply(this, args);
};
ret._fn_objs = fn_objs;
return ret;
}
String.prototype.format = Overload({
"array" : function (params) {
var reg = /{(\d+)}/gm;
return this.replace(reg, function (match, key) {
return params[~~key];
});
},
"object" : function (param) {
var reg = /{([^{}]+)}/gm;
return this.replace(reg, function (match, key) {
return param[key];
});
}
});
if (typeof String.prototype.startsWith !== 'function') {
String.prototype.startsWith = function (str){
return this.slice(0, str.length) === str;
};
String.prototype.endsWith = function (str){
return this.slice(-str.length) === str;
};
}
/*
Object.prototype.extend = function(obj){
for (var i in obj) {
//obj.hasOwnProperty(i) &&
(this[i] = obj[i]);
}
};*/
}();