DESKTOP-MK04A0R\chuck hace 3 años
padre
commit
49775f05a2
Se han modificado 6 ficheros con 200 adiciones y 0 borrados
  1. 30 0
      09/index.html
  2. 24 0
      10/index.html
  3. 23 0
      11/index.html
  4. 35 0
      12/index.html
  5. 83 0
      13/index.html
  6. 5 0
      README.md

+ 30 - 0
09/index.html

@@ -0,0 +1,30 @@
+<!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>
+        //1.默认值c
+        function add(a, b, c = 5){
+            return a+b+c;
+        }
+        console.log(add(1,2,3))
+
+        //2.与解构赋值结合
+        // host默认值
+        function connect({host='127.0.0.1',username,password,port}){
+            console.log(host)
+        }
+        connect({
+            //host:'localhost',
+            username:'root',
+            password:'root',
+            port:3306
+        })
+    </script>
+</body>
+</html>

+ 24 - 0
10/index.html

@@ -0,0 +1,24 @@
+<!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>rest</title>
+</head>
+<body>
+    <script>
+        //es5获取方式
+        function date(){
+            console.log(arguments)  //对象,并非数组
+        }
+        date(1,2,3,4);
+        //es6获取方式:rest参数放置最后,否则报错
+        function date1(a,b,...args){
+            console.log(args)   //数组
+        }
+        date1(1,2,3,4)
+
+    </script>
+</body>
+</html>

+ 23 - 0
11/index.html

@@ -0,0 +1,23 @@
+<!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>rest</title>
+</head>
+<body>
+    <script>
+        /**
+         * ... 将数组转换逗号分隔
+         */
+        const aa = [1,2,3,4]
+        function chun(){
+            console.log(arguments)
+        }
+        chun(aa)  //只有一个元素,是数组
+        chun(...aa)  //数组内部所有元素
+
+    </script>
+</body>
+</html>

+ 35 - 0
12/index.html

@@ -0,0 +1,35 @@
+<!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>rest</title>
+</head>
+<body>
+    <div></div>
+    <div></div>
+    <script>
+        /**
+         * 扩展运算应用
+         */
+        //1 数组合并
+        const aa = [1,2,3]
+        const bb = [3,4,5]
+        const cc = [...aa,...bb]
+        console.log(cc)  //1,2,3,3,4,5
+
+        //2 数组克隆 -- 注意仅支持浅拷贝
+        const dd = [6,7,8,9]
+        const ee = [...dd]
+        console.log(ee) // [6,7,8,9]
+
+        //3 将伪数组转换正数组
+        const divs = document.querySelectorAll('div')
+        console.log(divs)
+        const divArr = [...divs]
+        console.log(divArr)
+        //arguments也是伪数组,可以转换
+    </script>
+</body>
+</html>

+ 83 - 0
13/index.html

@@ -0,0 +1,83 @@
+<!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>rest</title>
+</head>
+<body>
+    <script>
+        /**
+         * 值唯一
+         * 不能运算
+         * 不能使用for in,可以使用reflect.ownkeys
+         */
+
+         //创建symbol
+         let s = Symbol()
+         console.log(s,typeof s)  //Symbol() "symbol"
+
+         let s1 = Symbol('chuck')  //描述字符串
+         let s2 = Symbol('chuck')  //描述字符串
+         console.log(s1)   //Symbol(chuck)
+         console.log(s1 === s2)  //false
+
+         let s3 = Symbol.for('chuck')  //函数对象
+         let s4 = Symbol.for('chuck')
+         console.log(s3,typeof s3)  //Symbol(chuck) "symbol"
+         console.log(s3 === s4) // true
+
+         //不能运算 否则报错
+         //let result = s + 100;
+
+         //数据类型
+         //USONB   you are so niubility
+         /**
+          * undefined
+          * string
+          * object
+          * null 
+          * symbol
+          */
+        
+        //symbol 使用场景
+        //给对象添加方法 up down -- 可以很安全的加入方法
+        let game = { }
+        let methods = {
+            up: Symbol(),
+            down: Symbol()
+        }
+        game[methods.up] = function(){}
+        game[methods.down] = function(){}
+
+        //2
+        let cc = {
+            name : 'chuck',
+            [Symbol('say')]:function(){}
+        }
+
+        // symbol 内置属性 共11个
+        /**
+         * hasInstance
+         * match
+         * replace
+         * isConcatSpreadable 
+         */
+        class Person{
+            //自动执行
+            static [Symbol.hasInstance](param){
+                console.log(param)  //{d:2}
+                console.log('检测')
+            }
+        }
+        let o = {d:2}
+        console.log(o instanceof Person)
+
+        const arr = [1,2,3]
+        const arr1 = [4,5,6]
+        arr1[Symbol.isConcatSpreadable] = false;//不可展开 合并
+        console.log(arr.concat(arr1))
+    </script>
+</body>
+</html>

+ 5 - 0
README.md

@@ -7,6 +7,11 @@
 * 06 es6对象简化写法
 * 07 箭头函数
 * 08 箭头函数应用场景
+* 09 函数参数默认值
+* 10 rest参数
+* 11 es6扩展运算符 ...
+* 12 扩展运算符应用
+* 13 symbol 新数组类型--表示第一无二的值
 
 ## 运行说明
     npm i