练习
This commit is contained in:
39
teaching/jwl/课件/es6/awaitasync.html
Normal file
39
teaching/jwl/课件/es6/awaitasync.html
Normal file
@@ -0,0 +1,39 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Document</title>
|
||||
<script>
|
||||
const fs = require('fs');
|
||||
|
||||
const readFile = function (fileName) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
fs.readFile(fileName, function(error, data) {
|
||||
if (error) return reject(error);
|
||||
resolve(data);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const gen = function* () {
|
||||
const f1 = yield readFile('/etc/fstab');
|
||||
const f2 = yield readFile('/etc/shells');
|
||||
console.log(f1.toString());
|
||||
console.log(f2.toString());
|
||||
};
|
||||
|
||||
|
||||
var gen1=async function(){
|
||||
const f1 = await readFile('/etc/fstab');
|
||||
const f2 = await readFile('/etc/shells');
|
||||
console.log(f1.toString());
|
||||
console.log(f2.toString());
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
113
teaching/jwl/课件/es6/fuxi.html
Normal file
113
teaching/jwl/课件/es6/fuxi.html
Normal file
@@ -0,0 +1,113 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Document</title>
|
||||
<script>
|
||||
// es6
|
||||
// let const
|
||||
// 解构赋值
|
||||
// async await
|
||||
// class
|
||||
// model 模块化
|
||||
// promise
|
||||
// set map weakset weakmap
|
||||
// for foreach for in while for of
|
||||
|
||||
// const set=new Set([1,2,3,3,3])
|
||||
// for(let i in set){
|
||||
// console.log(i,set[i])
|
||||
// }
|
||||
|
||||
</script>
|
||||
<script>
|
||||
const set=new Set([1,2,3,3,3])
|
||||
// console.log(set[2])
|
||||
for(let i of set){
|
||||
console.log(i,set[i])
|
||||
console.log(set)
|
||||
}
|
||||
|
||||
function zhanshi(){
|
||||
console.log(set,"lllk")
|
||||
const price=0
|
||||
}
|
||||
zhanshi()
|
||||
// console.log(price)
|
||||
|
||||
// 解构赋值
|
||||
// 对象 解构赋值 原则上来说 我们需要让属性名等于变量名
|
||||
// 特殊情况 如果说 属性名不等于属性值得话
|
||||
let {foo, baz}={foo:"aaa",bar:"bbb",baz:"ccc"}
|
||||
// foo aaaa
|
||||
// baz ccc
|
||||
// let { foo: baz } = { foo: 'aaa', bar: 'bbb' };
|
||||
console.log(foo, baz)
|
||||
|
||||
var promise=new Promise(function(resolve,reject){
|
||||
console.log(1111)
|
||||
resolve()
|
||||
})
|
||||
promise.then(()=>{
|
||||
console.log("success")
|
||||
})
|
||||
console.log(2222)
|
||||
console.log(1222223)
|
||||
setTimeout(function(){
|
||||
console.log("延迟后")
|
||||
},1000)
|
||||
|
||||
|
||||
// pro1.then(()=>{
|
||||
// pro2.then(()=>{
|
||||
// pro3.thne(()=>{
|
||||
// // .......
|
||||
// })
|
||||
// })
|
||||
// })
|
||||
|
||||
// 用同步的样子去写异步的函数 -----async 函数(异步操作的一个方式)
|
||||
|
||||
// function getlist(){
|
||||
// http.get("/userlist").then((res)=>{
|
||||
// console.log(res)
|
||||
// })
|
||||
// }
|
||||
|
||||
// async function getlist(){
|
||||
// let res=await http.get("/userlist")
|
||||
// console.log(res)
|
||||
// }
|
||||
|
||||
|
||||
// class
|
||||
class Creator{
|
||||
constructor(name){
|
||||
this.name=name,
|
||||
this.age=1
|
||||
}
|
||||
say(){
|
||||
console.log(123)
|
||||
}
|
||||
}
|
||||
|
||||
// extends
|
||||
|
||||
class Creator2 extends Creator{
|
||||
|
||||
}
|
||||
var obj=new Creator("A")
|
||||
var obj1=new Creator("B")
|
||||
console.log(obj)
|
||||
console.log(obj1)
|
||||
|
||||
var xiaoming=new Creator2("小明")
|
||||
console.log(xiaoming)
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
86
teaching/jwl/课件/es6/promise.html
Normal file
86
teaching/jwl/课件/es6/promise.html
Normal file
@@ -0,0 +1,86 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Document</title>
|
||||
<script>
|
||||
console.log("创建proimise之前")
|
||||
var promiseobj=new Promise((resolve,reject)=>{
|
||||
console.log("创建promise")
|
||||
if (this.readyState !== 4) {
|
||||
return;
|
||||
}
|
||||
if (this.status === 200) {
|
||||
cosnole.log("mysuccess")
|
||||
resolve(this.response);
|
||||
} else {
|
||||
console.log("myerror")
|
||||
reject(new Error(this.statusText));
|
||||
}
|
||||
})
|
||||
promiseobj.then(()=>{
|
||||
console.log("success")
|
||||
|
||||
})
|
||||
console.log("promise成功之后")
|
||||
|
||||
|
||||
// readyState
|
||||
// 用promise封装ajax
|
||||
const getJSON = function(url) {
|
||||
const promise = new Promise(function(resolve, reject){
|
||||
const handler = function() {
|
||||
console.log(this.readyState)
|
||||
console.log(this.status)
|
||||
if (this.readyState !== 4) {
|
||||
return;
|
||||
}
|
||||
if (this.status === 200) {
|
||||
resolve(this.response);
|
||||
} else {
|
||||
reject(new Error(this.statusText));
|
||||
}
|
||||
};
|
||||
const client = new XMLHttpRequest();
|
||||
client.open("GET", url);
|
||||
client.onreadystatechange = handler;
|
||||
client.responseType = "json";
|
||||
client.setRequestHeader("Accept", "application/json");
|
||||
client.send();
|
||||
|
||||
});
|
||||
|
||||
return promise;
|
||||
};
|
||||
|
||||
|
||||
// readystate 的五种状态
|
||||
// 0 - (未初始化)还没有调用send()方法
|
||||
// 1 - (载入)已调用send()方法,正在发送请求
|
||||
// 2 - (载入完成)send()方法执行完成,已经接收到全部响应内容
|
||||
// 3 - (交互)正在解析响应内容
|
||||
// 4 - (完成)响应内容解析完成,可以在客户端调用了
|
||||
|
||||
|
||||
|
||||
getJSON("/posts.json").then(function(json) {
|
||||
console.log('Contents: ' + json);
|
||||
}, function(error) {
|
||||
console.error('出错了', error);
|
||||
});
|
||||
|
||||
async function login(){
|
||||
http("./login.php").then((res)=>{
|
||||
console.log(res)
|
||||
})
|
||||
var res=http("./login.php")
|
||||
}
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user