forked from WangJia-mm/JavaScript201708
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
38 lines (36 loc) · 971 Bytes
/
utils.js
File metadata and controls
38 lines (36 loc) · 971 Bytes
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
var utils = (function () {
/*
* toArray:Converts an array of classes to an array
* @parameter:
* likeAry[object]:Class array to convert
* @return:
* ary[Array]:Convert completed array
* By Team on 2017-04-16 12:44
*/
function toArray(likeAry) {
var ary = [];
try {
ary = Array.prototype.slice.call(likeAry);
} catch (e) {
for (var i = 0, len = likeAry.length; i < len; i++) {
ary[ary.length] = likeAry[i];
}
}
return ary;
}
/*
* toJSON:Convert JSON string to JSON object
* @parameter:
* str[String]:JSON string
* @return:
* obj[Object]:JSON object
* By Team on 2017-04-16 12:48
*/
function toJSON(str) {
return 'JSON' in window ? JSON.parse(str) : eval('(' + str + ')');
}
return {
toArray: toArray,
toJSON: toJSON
}
})();