Skip to content

Commit 10b25df

Browse files
committed
add async await demo
1 parent 33c7ddb commit 10b25df

File tree

5 files changed

+82
-2
lines changed

5 files changed

+82
-2
lines changed

async await/a.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
name is a

async await/b.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
name is b ^_^

async await/demo.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const fs = require('fs');
2+
3+
function getFile1() {
4+
return new Promise(function(resolve, reject) {
5+
resolve(fs.readFileSync('a.txt'));
6+
});
7+
}
8+
9+
function getFile2() {
10+
return new Promise(function(resolve, reject) {
11+
resolve(fs.readFileSync('b.txt'));
12+
});
13+
}
14+
15+
async function show() {
16+
let data1 = await getFile1();
17+
let data2 = await getFile2();
18+
console.log(data1.toString());
19+
console.log(data2.toString());
20+
}
21+
22+
show();

web-knowledge/前端一点新东西.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,30 @@
163163
>
164164
> })
165165

166-
- https://itstrive.github.io/striveCode/html5-api/html5%20%E7%94%B5%E6%B1%A0%E4%BF%A1%E6%81%AF.html
166+
- https://itstrive.github.io/striveCode/html5-api/html5%20%E7%94%B5%E6%B1%A0%E4%BF%A1%E6%81%AF.html
167+
168+
- visibilitychange 页面可见性
169+
170+
> 用途: 多标签切换,浏览器最小化,提高用户体验
171+
172+
```javascript
173+
<video src="1.mp4" autoplay id="video1"></video>
174+
175+
<script>
176+
var oVideo=document.querySelector('#video1');
177+
178+
$(document).on('visibilitychange',function(){
179+
if(document.hidden){
180+
//oVideo.pause();
181+
$(oVideo).animate({volumn:0},1000,'linear',function(){
182+
oVideo.pause();
183+
});
184+
}else{
185+
oVideo.play();
186+
$(oVideo).animate({volumn:1},1000,'linear');
187+
}
188+
});
189+
</script>
190+
```
191+
192+

web-knowledge/前端技巧搜集.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,38 @@
115115
document.write("<script src=\"http://apps.bdimg.com/libs/vue/1.0.14/vue.js\"><\/script>");
116116
```
117117

118-
118+
6. open出来的窗口,获取父级window
119119

120+
```javascript
121+
var win=window.open('','MyName','width=200, height=100, left=300');
122+
123+
win.document.write('我是新页面');
124+
win.focus();
125+
win.opener.document.write('我是父级');
126+
```
120127

128+
7. 正则判断一个字符串中必须包含数字
121129

130+
(?=.*\d) 主要是这句,意思代表必须有数字
131+
132+
```javascript
133+
var reg=/^(?=.*\d)\w{2,5}$/g;
122134

135+
console.log(reg.test('h')); //false
136+
console.log(reg.test('good')); //false
137+
console.log(reg.test('w4ell')); //true
138+
reg.lastIndex=0; //别忘记调整index
139+
console.log(reg.test('5well')); //true
140+
```
141+
142+
那,校验字符串中必须包含数字以及大写字母呢?
143+
144+
```javascript
145+
var reg=/^(?=.*\d)(?=.*[A-Z])\w{2,5}$/g;
146+
147+
console.log(reg.test('h')); //false
148+
console.log(reg.test('Good5')); //true
149+
reg.lastIndex=0; //别忘记调整index
150+
console.log(reg.test('w4ell')); //false
151+
console.log(reg.test('5Well')); //true
152+
```

0 commit comments

Comments
 (0)