-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathisString.js
30 lines (29 loc) · 1007 Bytes
/
isString.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
String.isString = (function () {
var strToString = ('').toString,
hasBind = Function.prototype && Function.prototype.bind,
strToStrCall = hasBind && strToString.call.bind(strToString),
isString = function (str) {
/*@cc_on
@if (@_jscript_version >= 5) @*/
try {
hasBind ? strToStrCall(str) : strToString.call(str);
return true;
} catch (e) {
return false;
}
/*@end
@*/
};
return function (str) {
return typeof str === 'string' ||
(str && typeof str === 'object' &&
/*@cc_on
@if (@_jscript_version < 5.5)
/^\s*function\s*String\(\)\s*{\s*\[native code\]\s*}\s*$/.test(str.constructor)
@else @*/
isString(str)
/*@end
@*/
) || false;
};
})();