zsydgithub 1 жил өмнө
parent
commit
2558e78c82

+ 21 - 0
es6/15_symbol.html

@@ -0,0 +1,21 @@
+<!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>
+</head>
+<body>
+  <script>
+    /* 基本数据类型 number string boolean null undefined */
+    /* 独一无二的 不和其他的进行冲突 */
+    
+    // var a = Symbol('me')
+    let a = Symbol('school')
+    let b = Symbol('school')
+    console.log(a,b)
+    
+  </script>
+</body>
+</html>

+ 37 - 0
es6/16_set.html

@@ -0,0 +1,37 @@
+<!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>
+</head>
+<body>
+  <script>
+    var arr = [1,2,3,4,5,6,1,2,3,2,3,4,6]
+
+    var x = new Set(arr)
+    var arr2 = Array.from(x)
+    console.log(arr2)
+
+
+    function quchong(arr){
+      return Array.from(new Set(arr))
+    }
+    console.log(quchong([1,2,3,23,2,4,5,7,3,5,7]))
+    
+    var s1 = new Set([1,2,3,4])
+    console.log(s1)
+    s1.add(1)
+    console.log(s1)
+    s1.delete(1)
+    console.log(s1)
+
+
+
+    console.log(quchong['1','1','1'])
+
+
+  </script>
+</body>
+</html>

+ 39 - 0
es6/17_map.html

@@ -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>
+</head>
+<body>
+  <script>
+    /* map 数据结构 存放键值对 */
+    var obj = {
+      name: 'zs'
+    }
+    var a1 = new Map()
+    a1.set('age',20)
+    a1.set(obj,'aaa')
+    a1.set('name','lisi')
+    console.log(a1)
+
+
+    console.log(a1.get('name'))
+    console.log(a1.get(obj))
+
+
+    a1.set('name','Tom')
+    // console.log(a1.get('name'))
+    console.log(a1.has('name'))
+    console.log(a1.has('sex'))
+
+    console.log(a1.delete('sex'))
+    console.log(a1)
+
+    
+    a1.clear()
+    console.log(a1)
+  </script>
+</body>
+</html>

+ 98 - 0
es6/18_Promise.html

@@ -0,0 +1,98 @@
+<!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>
+</head>
+
+<body>
+  <script>
+    // console.log(4)
+    // setTimeout(()=>{
+    //   console.log(1)
+    //   setTimeout(()=>{
+    //     console.log(2)
+    //   },100)
+    //   setTimeout(()=>{
+    //     console.log(3)
+    //   },10)
+    // },0)
+    // console.log(5)
+
+    // let p1 = new Promise ((resolve,reject)=>{
+    //   reject()
+    //   resolve()
+    // }).then(()=>{
+    //   console.log('我成功了')
+    // }).catch(()=>{
+    //   console.log('我失败了')
+    // })
+    /* 
+      promise 有三种状态
+        pending 进行中
+        fullfiled 已经成功
+        rejected  已经失败
+      pending ->  fullfiled  or  pending -> rejected 
+      不可逆的  
+      1.当一个promise 被创建的时,初始状态为pending
+      2.当异步操作执行成功的时候,promise状态变为fullfiled 并且执行
+      then方法中回调函数
+      3.当异步操作执行失败的时候,promise状态变为rejected 并且执行
+      catch方法中的回调函数
+    */
+    let p1 = new Promise((resolve, reject) => {
+      setTimeout(()=>{
+        console.log(1)
+        reject()
+      },1000)
+      console.log(2)
+      resolve()
+
+    })
+    let p2 = new Promise ((resolve,reject)=>{
+      setTimeout(()=>{
+        console.log(3)
+        reject()
+      },800)
+      reject()
+    })
+    let p3 = new Promise ((resolve,reject)=>{
+      setTimeout(()=>{
+        console.log(4)
+        resolve()
+      },2000)
+      console.log(5)
+      reject()
+    })
+  
+    /* promise.all()将多个promise实例封装成一个promise实例 */
+    Promise.all([p1,p2,p3]).then(()=>{
+      console.log('ok')
+    }).catch(()=>{
+      console.log('error')
+    })
+/* 
+    Promise.race([p1,p2,p3]).then(()=>{
+      console.log('ok')
+    }).catch(()=>{
+      console.log('error')
+    }) */
+
+
+    // new Promise((resolve,reject)=>{
+    //   setTimeout(()=>{
+    //     console.log(1)
+    //     resolve()
+    //   },10)
+    // }).then(()=>{
+    //   console.log('ok')
+    // }).catch(()=>{
+    //   console.log('error')
+    // })
+  </script>
+</body>
+
+</html>