Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
易企天创
zui
提交
d7b7b1f4
Z
zui
项目概览
易企天创
/
zui
10 个月 前同步成功
通知
6
Star
0
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
37
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Z
zui
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
37
Issue
37
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
d7b7b1f4
编写于
6月 23, 2020
作者:
C
Catouse
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
* refactor date and string helpers.
上级
c56faadb
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
444 addition
and
238 deletion
+444
-238
src/js/date.js
src/js/date.js
+353
-184
src/js/string.js
src/js/string.js
+91
-54
未找到文件。
src/js/date.js
浏览文件 @
d7b7b1f4
...
...
@@ -5,242 +5,411 @@
* ========================================================================
* Copyright 2014-2020 cnezsoft.com; Licensed MIT
* ======================================================================== */
(
function
()
{
(
function
(
window
)
{
'
use strict
'
;
/**
* Ticks of a whole day
* @type {number}
*/
Date
.
ONEDAY_TICKS
=
24
*
3600
*
1000
;
const
ONEDAY_TICKS
=
24
*
3600
*
1000
;
/**
* Format date to a string
*
* @param string format
* @return string
*/
if
(
!
Date
.
prototype
.
format
)
{
Date
.
prototype
.
format
=
function
(
format
)
{
var
date
=
{
'
M+
'
:
this
.
getMonth
()
+
1
,
'
d+
'
:
this
.
getDate
(),
'
h+
'
:
this
.
getHours
(),
'
m+
'
:
this
.
getMinutes
(),
'
s+
'
:
this
.
getSeconds
(),
'
q+
'
:
Math
.
floor
((
this
.
getMonth
()
+
3
)
/
3
),
'
S+
'
:
this
.
getMilliseconds
()
};
if
(
/
(
y+
)
/i
.
test
(
format
))
{
format
=
format
.
replace
(
RegExp
.
$1
,
(
this
.
getFullYear
()
+
''
).
substr
(
4
-
RegExp
.
$1
.
length
));
}
for
(
var
k
in
date
)
{
if
(
new
RegExp
(
'
(
'
+
k
+
'
)
'
).
test
(
format
))
{
format
=
format
.
replace
(
RegExp
.
$1
,
RegExp
.
$1
.
length
==
1
?
date
[
k
]
:
(
'
00
'
+
date
[
k
]).
substr
((
''
+
date
[
k
]).
length
));
}
* Create a Date instance
* @param {Date|String|Number} date Date expression
* @return {Date}
*/
const
createDate
=
function
(
date
)
{
if
(
!
(
date
instanceof
Date
))
{
if
(
typeof
date
===
'
number
'
&&
date
<
10000000000
)
{
date
*=
1000
;
}
return
format
;
};
}
date
=
new
Date
(
date
);
}
return
date
;
};
/**
* Add milliseconds to the date
* @param {number} value
* Get timestamp of a Date
* @param {Date|String|Number} date Date expression
* @return {number}
*/
if
(
!
Date
.
prototype
.
addMilliseconds
)
{
Date
.
prototype
.
addMilliseconds
=
function
(
value
)
{
this
.
setTime
(
this
.
getTime
()
+
value
);
return
this
;
};
}
const
getTimestamp
=
function
(
date
)
{
return
createDate
(
date
).
getTime
();
};
/**
* Add days to the date
* @param {number} days
* Format date to a string
*
* @param {Date|String|Number} Date date expression
* @param {string} [format='yyyy-MM-dd hh:mm:ss'] Date format string
* @return {string}
*/
if
(
!
Date
.
prototype
.
addDays
)
{
Date
.
prototype
.
addDays
=
function
(
days
)
{
this
.
addMilliseconds
(
days
*
Date
.
ONEDAY_TICKS
);
return
this
;
const
formatDate
=
function
(
date
,
format
)
{
date
=
createDate
(
date
);
if
(
format
===
undefined
)
{
format
=
'
yyyy-MM-dd hh:mm:ss
'
;
}
var
map
=
{
'
M+
'
:
date
.
getMonth
()
+
1
,
'
d+
'
:
date
.
getDate
(),
'
h+
'
:
date
.
getHours
(),
'
m+
'
:
date
.
getMinutes
(),
'
s+
'
:
date
.
getSeconds
(),
'
q+
'
:
Math
.
floor
((
date
.
getMonth
()
+
3
)
/
3
),
'
S+
'
:
date
.
getMilliseconds
()
};
}
if
(
/
(
y+
)
/i
.
test
(
format
))
{
format
=
format
.
replace
(
RegExp
.
$1
,
(
date
.
getFullYear
()
+
''
).
substr
(
4
-
RegExp
.
$1
.
length
));
}
for
(
var
k
in
map
)
{
if
(
new
RegExp
(
'
(
'
+
k
+
'
)
'
).
test
(
format
))
{
format
=
format
.
replace
(
RegExp
.
$1
,
RegExp
.
$1
.
length
==
1
?
map
[
k
]
:
(
'
00
'
+
map
[
k
]).
substr
((
''
+
map
[
k
]).
length
));
}
}
return
format
;
};
/**
* Add milliseconds to the date
* @param {Date} Date date
* @param {number} milliseconds milliseconds value
* @return {Date}
*/
const
addMilliseconds
=
function
(
date
,
milliseconds
)
{
date
.
setTime
(
date
.
getTime
()
+
milliseconds
);
return
date
;
};
/**
* Clone a new date instane from the date
* Add milliseconds to the date
* @param {Date} date date
* @param {number} days days value
* @return {Date}
*/
if
(
!
Date
.
prototype
.
clone
)
{
Date
.
prototype
.
clone
=
function
()
{
var
date
=
new
Date
();
date
.
setTime
(
this
.
getTime
());
return
date
;
};
}
const
addDays
=
function
(
date
,
days
)
{
return
addMilliseconds
(
date
,
days
*
ONEDAY_TICKS
);
};
/**
* Clone date to a new instance
* @param {Date|String|Number} date date expression
*/
const
cloneDate
=
function
(
date
)
{
return
new
Date
(
createDate
(
date
).
getTime
());
};
/**
* Judge the year is in a leap year
* @param
{integer}
year
* @return {
B
oolean}
* @param
{number}
year
* @return {
b
oolean}
*/
if
(
!
Date
.
isLeapYear
)
{
Date
.
isLeapYear
=
function
(
year
)
{
return
(((
year
%
4
===
0
)
&&
(
year
%
100
!==
0
))
||
(
year
%
400
===
0
));
};
}
if
(
!
Date
.
getDaysInMonth
)
{
/**
* Get days number of the date
* @param {integer} year
* @param {integer} month
* @return {integer}
*/
Date
.
getDaysInMonth
=
function
(
year
,
month
)
{
return
[
31
,
(
Date
.
isLeapYear
(
year
)
?
29
:
28
),
31
,
30
,
31
,
30
,
31
,
31
,
30
,
31
,
30
,
31
][
month
];
};
}
const
isLeapYear
=
function
(
year
)
{
return
((
year
%
4
===
0
)
&&
(
year
%
100
!==
0
))
||
(
year
%
400
===
0
);
};
/**
* Judge the date is in a leap year
* @return {Boolean}
* Get days number of the date
* @param {number} year
* @param {number} month
* @return {number}
*/
if
(
!
Date
.
prototype
.
isLeapYear
)
{
Date
.
prototype
.
isLeapYear
=
function
()
{
return
Date
.
isLeapYear
(
this
.
getFullYear
());
};
}
const
getDaysInMonth
=
function
(
year
,
month
)
{
return
[
31
,
(
isLeapYear
(
year
)
?
29
:
28
),
31
,
30
,
31
,
30
,
31
,
31
,
30
,
31
,
30
,
31
][
month
];
};
/**
* Clear time part of the date
* @return {date}
*/
if
(
!
Date
.
prototype
.
clearTime
)
{
Date
.
prototype
.
clearTime
=
function
()
{
this
.
setHours
(
0
);
this
.
setMinutes
(
0
);
this
.
setSeconds
(
0
);
this
.
setMilliseconds
(
0
);
return
this
;
};
}
* Get days number of the date
* @param {Date} date date
* @return {number}
*/
const
getDaysOfThisMonth
=
function
(
date
)
{
return
getDaysInMonth
(
date
.
getFullYear
(),
date
.
getMonth
());
};
/**
* Get days of this month of the date
* @return {integer}
* Clear time part of the date
* @param {Date} date date
* @return {Date}
*/
if
(
!
Date
.
prototype
.
getDaysInMonth
)
{
Date
.
prototype
.
getDaysInMonth
=
function
()
{
return
Date
.
getDaysInMonth
(
this
.
getFullYear
(),
this
.
getMonth
());
};
}
const
clearTime
=
function
(
date
)
{
date
.
setHours
(
0
);
date
.
setMinutes
(
0
);
date
.
setSeconds
(
0
);
date
.
setMilliseconds
(
0
);
return
date
;
};
/**
* Add months to the date
* @param {date} value
*/
if
(
!
Date
.
prototype
.
addMonths
)
{
Date
.
prototype
.
addMonths
=
function
(
value
)
{
var
n
=
this
.
getDate
();
this
.
setDate
(
1
);
this
.
setMonth
(
this
.
getMonth
()
+
value
);
this
.
setDate
(
Math
.
min
(
n
,
this
.
getDaysInMonth
()));
return
this
;
};
}
* @param {Date} date date
* @param {number} monthsCount
* @return {Date}
*/
const
addMonths
=
function
(
date
,
monthsCount
)
{
var
n
=
date
.
getDate
();
date
.
setDate
(
1
);
date
.
setMonth
(
date
.
getMonth
()
+
monthsCount
);
date
.
setDate
(
Math
.
min
(
n
,
getDaysOfThisMonth
(
date
)));
return
date
;
};
/**
* Get last week day of the date
* @param {integer} day
* @return {date}
* @param {Date} date date
* @param {number} [day=1] 1 ~ 7
* @return {Date}
*/
if
(
!
Date
.
prototype
.
getLastWeekday
)
{
Date
.
prototype
.
getLastWeekday
=
function
(
day
)
{
day
=
day
||
1
;
var
d
=
this
.
clone
();
while
(
d
.
getDay
()
!=
day
)
{
d
.
addDays
(
-
1
);
}
d
.
clearTime
();
return
d
;
};
}
const
getLastWeekday
=
function
(
date
,
day
)
{
day
=
day
||
1
;
var
d
=
new
Date
(
date
.
getTime
());
while
(
d
.
getDay
()
!=
day
)
{
d
=
addDays
(
d
,
-
1
);
}
return
clearTime
(
d
);
};
/**
* Judge the date is same day as another date
* @param {date} date
* @return {Boolean}
* Judge the date is same day with another date
* @param {Date} date1
* @param {Date} date2
* @return {boolean}
*/
if
(
!
Date
.
prototype
.
isSameDay
)
{
Date
.
prototype
.
isSameDay
=
function
(
date
)
{
return
date
.
toDateString
()
===
this
.
toDateString
();
};
}
const
isSameDay
=
function
(
date1
,
date2
)
{
return
date1
.
toDateString
()
===
date2
.
toDateString
();
};
/**
* Judge the date is in same week as another date
* @param {date} date
* @return {Boolean}
* Judge the date is in same week with another date
* @param {Date} date1
* @param {Date} date2
* @return {boolean}
*/
if
(
!
Date
.
prototype
.
isSameWeek
)
{
Date
.
prototype
.
isSameWeek
=
function
(
date
)
{
var
weekStart
=
this
.
getLastWeekday
();
var
weekEnd
=
weekStart
.
clone
().
addDays
(
7
);
return
date
>=
weekStart
&&
date
<
weekEnd
;
};
}
const
isSameWeek
=
function
(
date1
,
date2
)
{
var
weekStart
=
getLastWeekday
(
date1
);
var
weekEnd
=
addDays
(
cloneDate
(
weekStart
),
7
);
return
date2
>=
weekStart
&&
date2
<
weekEnd
;
};
/**
* Judge the date is in same year as another date
* @param {date} date
* @return {Boolean}
* Judge the date is in same year with another date
* @param {Date} date1
* @param {Date} date2
* @return {boolean}
*/
if
(
!
Date
.
prototype
.
isSameYear
)
{
Date
.
prototype
.
isSameYear
=
function
(
date
)
{
return
this
.
getFullYear
()
===
date
.
getFullYear
();
};
}
const
isSameYear
=
function
(
date1
,
date2
)
{
return
date1
.
getFullYear
()
===
date2
.
getFullYear
();
};
/**
* Create an date instance with string, timestamp or date instance
* @param {Date|String|Number} date
* @return {Date}
*/
if
(
!
Date
.
create
)
{
Date
.
create
=
function
(
date
)
{
if
(
!
(
date
instanceof
Date
))
{
if
(
typeof
date
===
'
number
'
&&
date
<
10000000000
)
{
date
*=
1000
;
}
date
=
new
Date
(
date
);
}
return
date
;
};
const
exports
=
{
formatDate
:
formatDate
,
createDate
:
createDate
,
date
:
{
ONEDAY_TICKS
:
ONEDAY_TICKS
,
create
:
createDate
,
getTimestamp
:
getTimestamp
,
format
:
formatDate
,
addMilliseconds
:
addMilliseconds
,
addDays
:
addDays
,
cloneDate
:
cloneDate
,
isLeapYear
:
isLeapYear
,
getDaysInMonth
:
getDaysInMonth
,
getDaysOfThisMonth
:
getDaysOfThisMonth
,
clearTime
:
clearTime
,
addMonths
:
addMonths
,
getLastWeekday
:
getLastWeekday
,
isSameDay
:
isSameDay
,
isSameWeek
:
isSameWeek
,
isSameYear
:
isSameYear
,
}
};
if
(
window
.
$
&&
window
.
$
.
zui
)
{
$
.
zui
(
exports
);
}
else
{
window
.
dateHelper
=
exports
.
date
;
}
if
(
!
Date
.
timestamp
)
{
Date
.
timestamp
=
function
(
date
)
{
if
(
typeof
date
===
'
number
'
)
{
if
(
date
<
10000000000
)
{
date
*=
1000
;
}
}
else
{
date
=
Date
.
create
(
date
).
getTime
();
}
return
date
;
};
if
(
!
window
.
noDatePrototypeHelper
)
{
/**
* Ticks of a whole day
* @type {number}
*/
Date
.
ONEDAY_TICKS
=
ONEDAY_TICKS
;
/**
* Format date to a string
*
* @param string format
* @return string
*/
if
(
!
Date
.
prototype
.
format
)
{
Date
.
prototype
.
format
=
function
(
format
)
{
return
formatDate
(
this
,
format
);
};
}
/**
* Add milliseconds to the date
* @param {number} value
*/
if
(
!
Date
.
prototype
.
addMilliseconds
)
{
Date
.
prototype
.
addMilliseconds
=
function
(
value
)
{
return
addMilliseconds
(
this
,
value
);
};
}
/**
* Add days to the date
* @param {number} days
*/
if
(
!
Date
.
prototype
.
addDays
)
{
Date
.
prototype
.
addDays
=
function
(
days
)
{
return
addDays
(
this
,
days
);
};
}
/**
* Clone a new date instane from the date
* @return {Date}
*/
if
(
!
Date
.
prototype
.
clone
)
{
Date
.
prototype
.
clone
=
function
()
{
return
cloneDate
(
this
);
};
}
/**
* Judge the year is in a leap year
* @param {integer} year
* @return {Boolean}
*/
if
(
!
Date
.
isLeapYear
)
{
Date
.
isLeapYear
=
function
(
year
)
{
return
isLeapYear
(
year
);
};
}
if
(
!
Date
.
getDaysInMonth
)
{
/**
* Get days number of the date
* @param {integer} year
* @param {integer} month
* @return {integer}
*/
Date
.
getDaysInMonth
=
function
(
year
,
month
)
{
return
getDaysInMonth
(
year
,
month
);
};
}
/**
* Judge the date is in a leap year
* @return {Boolean}
*/
if
(
!
Date
.
prototype
.
isLeapYear
)
{
Date
.
prototype
.
isLeapYear
=
function
()
{
return
isLeapYear
(
this
.
getFullYear
());
};
}
/**
* Clear time part of the date
* @return {date}
*/
if
(
!
Date
.
prototype
.
clearTime
)
{
Date
.
prototype
.
clearTime
=
function
()
{
return
clearTime
(
this
);
};
}
/**
* Get days of this month of the date
* @return {integer}
*/
if
(
!
Date
.
prototype
.
getDaysInMonth
)
{
Date
.
prototype
.
getDaysInMonth
=
function
()
{
return
getDaysOfThisMonth
(
this
);
};
}
/**
* Add months to the date
* @param {number} monthsCount
*/
if
(
!
Date
.
prototype
.
addMonths
)
{
Date
.
prototype
.
addMonths
=
function
(
monthsCount
)
{
return
addMonths
(
this
,
monthsCount
);
};
}
/**
* Get last week day of the date
* @param {integer} day
* @return {date}
*/
if
(
!
Date
.
prototype
.
getLastWeekday
)
{
Date
.
prototype
.
getLastWeekday
=
function
(
day
)
{
return
getLastWeekday
(
this
,
day
);
};
}
/**
* Judge the date is same day as another date
* @param {Date} date
* @return {Boolean}
*/
if
(
!
Date
.
prototype
.
isSameDay
)
{
Date
.
prototype
.
isSameDay
=
function
(
date
)
{
return
isSameDay
(
date
,
this
);
};
}
/**
* Judge the date is in same week as another date
* @param {Date} date
* @return {Boolean}
*/
if
(
!
Date
.
prototype
.
isSameWeek
)
{
Date
.
prototype
.
isSameWeek
=
function
(
date
)
{
return
isSameWeek
(
date
,
this
);
};
}
/**
* Judge the date is in same year as another date
* @param {Date} date
* @return {Boolean}
*/
if
(
!
Date
.
prototype
.
isSameYear
)
{
Date
.
prototype
.
isSameYear
=
function
(
date
)
{
return
isSameYear
(
this
,
date
);
};
}
/**
* Create an date instance with string, timestamp or date instance
* @param {Date|String|Number} date
* @return {Date}
*/
if
(
!
Date
.
create
)
{
Date
.
create
=
function
(
date
)
{
return
createDate
(
date
);
};
}
if
(
!
Date
.
timestamp
)
{
Date
.
timestamp
=
function
(
date
)
{
return
getTimestamp
(
date
);
};
}
}
}());
}(
window
));
src/js/string.js
浏览文件 @
d7b7b1f4
...
...
@@ -6,81 +6,118 @@
* Copyright (c) 2014-2016 cnezsoft.com; Licensed MIT
* ======================================================================== */
(
function
()
{
'
use strict
'
;
/**
* Format string with argument list or object
* @param {String} str
* @param {object | arguments} args
* @return {String}
*/
if
(
!
String
.
prototype
.
format
)
{
String
.
prototype
.
format
=
function
(
args
)
{
var
result
=
this
;
if
(
arguments
.
length
>
0
)
{
var
reg
;
if
(
arguments
.
length
<=
2
&&
typeof
(
args
)
==
'
object
'
)
{
for
(
var
key
in
args
)
{
if
(
args
[
key
]
!==
undefined
)
{
reg
=
new
RegExp
(
'
(
'
+
(
arguments
[
1
]
?
arguments
[
1
].
replace
(
'
0
'
,
key
)
:
'
{
'
+
key
+
'
}
'
)
+
'
)
'
,
'
g
'
);
result
=
result
.
replace
(
reg
,
args
[
key
]);
}
const
formatString
=
function
(
str
,
args
)
{
if
(
arguments
.
length
>
1
)
{
var
reg
;
if
(
arguments
.
length
==
2
&&
typeof
(
args
)
==
"
object
"
)
{
for
(
var
key
in
args
)
{
if
(
args
[
key
]
!==
undefined
)
{
reg
=
new
RegExp
(
"
({
"
+
key
+
"
})
"
,
"
g
"
);
str
=
str
.
replace
(
reg
,
args
[
key
]);
}
}
else
{
for
(
var
i
=
0
;
i
<
arguments
.
length
;
i
++
)
{
if
(
arguments
[
i
]
!==
undefined
)
{
reg
=
new
RegExp
(
'
({[
'
+
i
+
'
]})
'
,
'
g
'
);
result
=
result
.
replace
(
reg
,
arguments
[
i
]
);
}
}
}
else
{
for
(
var
i
=
1
;
i
<
arguments
.
length
;
i
++
)
{
if
(
arguments
[
i
]
!==
undefined
)
{
reg
=
new
RegExp
(
"
({[
"
+
(
i
-
1
)
+
"
]})
"
,
"
g
"
);
str
=
str
.
replace
(
reg
,
arguments
[
i
]);
}
}
}
return
result
;
}
;
}
}
return
str
;
}
;
/**
* Judge the string is a integer number
*
* @param {String} str
* @access public
* @return
bool
* @return
{Boolean}
*/
if
(
!
String
.
prototype
.
isNum
)
{
String
.
prototype
.
isNum
=
function
(
s
)
{
if
(
s
!==
null
)
{
var
r
,
re
;
re
=
/
\d
*/i
;
r
=
s
.
match
(
re
);
return
(
r
==
s
)
?
true
:
false
;
}
return
false
;
};
}
const
isNum
=
function
(
str
)
{
if
(
str
!==
null
)
{
var
r
,
re
;
re
=
/
\d
*/i
;
r
=
str
.
match
(
re
);
return
(
r
==
str
)
?
true
:
false
;
}
return
false
;
};
if
(
!
String
.
prototype
.
endsWith
)
{
String
.
prototype
.
endsWith
=
function
(
searchString
,
position
)
{
var
subjectString
=
this
.
toString
();
if
(
position
===
undefined
||
position
>
subjectString
.
length
)
{
position
=
subjectString
.
length
;
}
position
-=
searchString
.
length
;
var
lastIndex
=
subjectString
.
indexOf
(
searchString
,
position
);
return
lastIndex
!==
-
1
&&
lastIndex
===
position
;
};
}
const
exports
=
{
formatString
:
formatString
,
string
:
{
format
:
formatString
,
isNum
:
isNum
,
}
};
if
(
!
String
.
prototype
.
startsWith
)
{
String
.
prototype
.
startsWith
=
function
(
searchString
,
position
)
{
position
=
position
||
0
;
return
this
.
lastIndexOf
(
searchString
,
position
)
===
position
;
};
if
(
window
.
$
&&
window
.
$
.
zui
)
{
$
.
zui
(
exports
);
}
else
{
window
.
stringHelper
=
exports
.
string
;
}
if
(
!
String
.
prototype
.
includes
)
{
String
.
prototype
.
includes
=
function
()
{
return
String
.
prototype
.
indexOf
.
apply
(
this
,
arguments
)
!==
-
1
;
};
}
if
(
!
window
.
noStringPrototypeHelper
)
{
/**
* Format string with argument list or object
* @param {object | arguments} args
* @return {String}
*/
if
(
!
String
.
prototype
.
format
)
{
String
.
prototype
.
format
=
function
()
{
var
args
=
[].
slice
.
call
(
arguments
);
args
.
unshift
(
this
);
return
formatString
.
apply
(
this
,
args
);
};
}
/**
* Judge the string is a integer number
*
* @access public
* @return bool
*/
if
(
!
String
.
prototype
.
isNum
)
{
String
.
prototype
.
isNum
=
function
()
{
return
isNum
(
this
);
};
}
// https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith
if
(
!
String
.
prototype
.
endsWith
)
{
String
.
prototype
.
endsWith
=
function
(
search
,
this_len
)
{
if
(
this_len
===
undefined
||
this_len
>
this
.
length
)
{
this_len
=
this
.
length
;
}
return
this
.
substring
(
this_len
-
search
.
length
,
this_len
)
===
search
;
};
}
// https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith
if
(
!
String
.
prototype
.
startsWith
)
{
Object
.
defineProperty
(
String
.
prototype
,
'
startsWith
'
,
{
value
:
function
(
search
,
pos
)
{
pos
=
!
pos
||
pos
<
0
?
0
:
+
pos
;
return
this
.
substring
(
pos
,
pos
+
search
.
length
)
===
search
;
}
});
}
if
(
!
String
.
prototype
.
includes
)
{
String
.
prototype
.
includes
=
function
()
{
return
String
.
prototype
.
indexOf
.
apply
(
this
,
arguments
)
!==
-
1
;
};
}
}
})();
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录