forked from ygs-code/vue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bailRE.html
39 lines (37 loc) · 1.02 KB
/
bailRE.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<script>
/**
* Parse simple path.
* 解析简单路径。
*/
var bailRE = /[^\w.$]/; //匹配任何字符 已点结束的字符串
function parsePath(path) {
console.log(bailRE.test(path))
if (bailRE.test(path)) { //匹配上 返回 true
return
}
//匹配不上 path在已点分割
var segments = path.split('.');
return function (obj) {
for (var i = 0; i < segments.length; i++) {
//如果有参数则返回真
if (!obj) {
return
}
//将对象中的一个key值 赋值给该对象 相当于 obj = obj[segments[segments.length-1]];
obj = obj[segments[i]];
}
//否则返回一个对象
return obj
}
}
parsePath('~123@')
</script>
</body>
</html>