Skip to content

Commit

Permalink
20180629
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangyue0503 committed Jun 29, 2018
1 parent 782d97e commit 208bd43
Show file tree
Hide file tree
Showing 23 changed files with 732 additions and 0 deletions.
31 changes: 31 additions & 0 deletions es6/jses6xl/4/all.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>

</head>

<body>

<script>
Promise.all([
new Promise((s, e) => {
s();
}), new Promise((s, e) => {
s();
}), new Promise((s, e) => {
e();
})
]).then(() => {
console.log(1);
}).catch(()=>{
console.log(2);
});
</script>
</body>

</html>
25 changes: 25 additions & 0 deletions es6/jses6xl/4/catch.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>

</head>
<body>

<script>
new Promise((succ,error)=>{
error('asdasddsd');
}).then(()=>{

}).catch(x=>{
console.log(x);
return 'asdfasdf';
}).then(f=>{
console.log(f);
})
</script>
</body>
</html>
34 changes: 34 additions & 0 deletions es6/jses6xl/4/demo1.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
*{margin:0;padding:0;list-style: none;}
div{
width:200px;height:200px;background:#ccc;
}
</style>
</head>
<body>
<input id='ipt' type="button" value="ddd">
<div id="div1"></div>
<script>
let index = 0;
let div1 = document.getElementById('div1');
let ipt = document.getElementById('ipt');
ipt.onclick = x => {
index++;
new Promise((succ,error)=>{
index%2==1?succ():error();
}).then(()=>{
div1.style.display = 'none';
},()=>{
div1.style.display = 'block';
});
}
</script>
</body>
</html>
26 changes: 26 additions & 0 deletions es6/jses6xl/4/map.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>

</head>

<body>
<script>
var map = new Map();

map.set(
[
['111', 222],
['222', 333]
]
);
console.log(map);
</script>
</body>

</html>
31 changes: 31 additions & 0 deletions es6/jses6xl/4/promise.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<script>
function showPromise(res){
return new Promise((resolve,reject)=>{
resolve(res);
}).then(x=>{console.log(res);})
}

showPromise('haha');
showPromise('haha11');

// var pro = new Promise(function(reslove,reject){
// reslove('heiehiehi');
// }).then(function(x){
// alert('成功'+x);
// },function(){
// alert('失败');
// });

// console.log(pro);
</script>
</body>
</html>
26 changes: 26 additions & 0 deletions es6/jses6xl/4/promise2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<script>
new Promise(function(reslove,reject){
reslove('heiehiehi');
}).then(function(x){
alert(x);
return 'asdfasdf';
},function(){
alert('失败');
}).then(function(x){
alert(x);
return '1010101';
}).then(function(x){
alert(x);
})
</script>
</body>
</html>
28 changes: 28 additions & 0 deletions es6/jses6xl/4/promise3.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>

</head>

<body>

<script>
new Promise((success, error) => {
success('123');
}).then((x) => {
throw x;
return x + 1;
})
.then((f) => {
console.log(f);
})
.then(() => {})
</script>
</body>

</html>
28 changes: 28 additions & 0 deletions es6/jses6xl/4/promise4.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>

</head>

<body>

<script>
Promise.resolve('123123111').then((f)=>{
console.log(f);
}).catch(()=>{
console.log(123123);
});
Promise.reject('123123111').then((f)=>{
console.log(f);
}).catch(()=>{
console.log(123123);
});
</script>
</body>

</html>
49 changes: 49 additions & 0 deletions es6/jses6xl/4/promise5-ajax.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>

</head>

<body>
<script>
function ajax(url) {
return new Promise((s, e) => {
var ajax = new XMLHttpRequest();
ajax.open('get', url, true);
ajax.send();
ajax.onload = function () {
s(ajax.responseText);
};
ajax.onerror = function(){
e();
}
}).then((text)=>{
console.log(text);
}).catch(()=>{
console.log('失败了');
});
}

ajax('http://localhost:3000');


// var ajax = new XMLHttpRequest();
// ajax.open('get', 'http://localhost:3000', true);
// ajax.send();
// ajax.onload = function () {
// console.log(ajax.responseText);
// }
// ajax.onerror = function () {
// console.log(ajax.status);
// }
// console.log(ajax.responseText);
// console.log(ajax);
</script>
</body>

</html>
30 changes: 30 additions & 0 deletions es6/jses6xl/4/race.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>

</head>

<body>

<script>
Promise.race([
new Promise((s, e) => {
// s('555');
setTimeout(s,1000,'1');
}), new Promise((s, e) => {
setTimeout(s,1200,'2');
}), new Promise((s, e) => {
setTimeout(s,1400,'3');
})
]).then((x) => {
console.log(x);
}, () => {})
</script>
</body>

</html>
22 changes: 22 additions & 0 deletions es6/jses6xl/4/test-server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const http = require('http');

const hostname = '127.0.0.1';
const port = 3000;

const server = http.createServer((req,res)=>{
res.statusCode = 200;
res.setHeader('Content-Type','text/plain');
res.setHeader('Access-Control-Allow-Origin','*');

Object.keys(require.cache).forEach(function(key){
delete require.cache[key];
});



res.end('aaaal;ksjdflkasjdf');
});

server.listen(port,hostname,()=>{
console.log(`Server running at http://${hostname}:${port}/`)
});
19 changes: 19 additions & 0 deletions es6/jses6xl/4/throw.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>

</head>
<body>

<script>
// throw 'alakskldjf';
console.warn('asdfasdf');
console.error('alskdjflkass');
console.log(111);
</script>
</body>
</html>
18 changes: 18 additions & 0 deletions es6/jses6xl/4/worker.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>

</head>

<body>
<script>

</script>
</body>

</html>
Loading

0 comments on commit 208bd43

Please sign in to comment.