DESKTOP-MK04A0R\chuck 3 gadi atpakaļ
vecāks
revīzija
45c918efa5
14 mainītis faili ar 199 papildinājumiem un 0 dzēšanām
  1. 41 0
      21/index.html
  2. 40 0
      22/index.html
  3. 7 0
      23/dist/app.js
  4. 6 0
      23/dist/index.js
  5. 8 0
      23/dist/index2.js
  6. 7 0
      23/dist/index3.js
  7. 16 0
      23/home.html
  8. 38 0
      23/index.html
  9. 7 0
      23/src/app.js
  10. 6 0
      23/src/index.js
  11. 10 0
      23/src/index2.js
  12. 7 0
      23/src/index3.js
  13. 3 0
      README.md
  14. 3 0
      package.json

+ 41 - 0
21/index.html

@@ -0,0 +1,41 @@
+<!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.EPSILON 浮点型计算
+        console.log(0.1 + 0.2 === 0.3)
+        function equal(a,b){
+            return Math.abs(a-b)<Number.EPSILON
+        }
+        console.log(equal(0.1+0.2,0.3))
+
+        //二进制和八进制
+        let b = 0b1010
+        let o = 0o777
+        let d = 100
+        let x = 0xff
+
+        //Number.isFinite 检测一个数值是否为有限数
+        //Number.isNaN 检测一个值是否为NaN
+        //Number.parseInt 字符串转化数字
+        console.log(Number.parseInt('123aaa'))  // 123
+        console.log(Number.parseFloat('2.3dr')) // 2.3
+
+        // Number.isInteger 判断是否整数
+        console.log(Number.isInteger('123')) // false
+
+        //Number.trunc 将小数部分去掉
+
+        //Math.sign 判断一个数是正数、负数、0
+        console.log(Math.sign(0)) //0
+        console.log(Math.sign(100)) //1
+        console.log(Math.sign(-100))  //-1
+    </script>
+</body>
+</html>

+ 40 - 0
22/index.html

@@ -0,0 +1,40 @@
+<!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>
+        //Object.is 判断两个值是否完全相等
+        console.log(Object.is(123,123)) // true
+        console.log(Object.is(NaN,NaN)) //true
+        console.log(NaN === NaN)  //false
+
+        //Object.assgin 对象合并
+        const config1 = {
+            a:1,
+            b:2
+        }
+        const config2 = {
+            c:3,
+            a:5
+        }
+        console.log(Object.assign(config1,config2)) //{a: 5, b: 2, c: 3}
+
+        // Object.setPrototypeof 设置原型对象
+        const school = {
+            name:'qinghua'
+        }
+        const cities = {
+            xiaoqu:['北京','上海']
+        }
+        Object.setPrototypeOf(school,cities)
+        console.log(Object.getPrototypeOf(school))
+        console.log(school)
+
+    </script>
+</body>
+</html>

+ 7 - 0
23/dist/app.js

@@ -0,0 +1,7 @@
+import * as m1 from './index.js';
+import * as m2 from './index2.js';
+import * as m3 from './index3.js';
+
+console.log(m1);
+console.log(m2);
+console.log(m3);

+ 6 - 0
23/dist/index.js

@@ -0,0 +1,6 @@
+//分别暴露
+export let school = 'beijingdaxue';
+
+export function teach() {
+    console.log('teaching');
+}

+ 8 - 0
23/dist/index2.js

@@ -0,0 +1,8 @@
+//
+let school = 'beijingdaxue';
+
+function teach() {
+    console.log('teaching');
+}
+
+export { school, teach };

+ 7 - 0
23/dist/index3.js

@@ -0,0 +1,7 @@
+
+export default {
+    school: 'hihihi',
+    change: function () {
+        console.log('hello');
+    }
+};

+ 16 - 0
23/home.html

@@ -0,0 +1,16 @@
+<!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 babel转换: babel-cli babel-preset-env browserify(webpack)
+         */
+    </script>
+</body>
+</html>

+ 38 - 0
23/index.html

@@ -0,0 +1,38 @@
+<!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 src="./src/app.js" type="module"></script> -->
+    <script type="module">
+        //1 引入
+        import * as m from './src/index.js'
+        console.log(m)
+
+        import * as m2 from './src/index2.js'
+        console.log(m2)
+
+        import * as m3 from './src/index3.js'
+        console.log(m3)
+
+        //2 引入 解构赋值形式
+        import {school,teach} from './src/index.js'
+        console.log(school)
+
+        import {school as school2} from './src/index2.js'
+        console.log(school2)
+
+        import {default as m4} from './src/index3.js'
+        console.log(m4)
+
+        //3 引入 简便形式 只针对默认暴露
+        import m5 from './src/index3.js'
+        console.log(m5)
+
+    </script>
+</body>
+</html>

+ 7 - 0
23/src/app.js

@@ -0,0 +1,7 @@
+import * as m1 from './index.js'
+import * as m2 from './index2.js'
+import * as m3 from './index3.js'
+
+console.log(m1)
+console.log(m2)
+console.log(m3)

+ 6 - 0
23/src/index.js

@@ -0,0 +1,6 @@
+//分别暴露
+export let school = 'beijingdaxue'
+
+export function teach(){
+    console.log('teaching')
+}

+ 10 - 0
23/src/index2.js

@@ -0,0 +1,10 @@
+//
+let school = 'beijingdaxue'
+
+function teach(){
+    console.log('teaching')
+}
+
+export {
+    school,teach
+}

+ 7 - 0
23/src/index3.js

@@ -0,0 +1,7 @@
+
+export default {
+    school: 'hihihi',
+    change: function(){
+        console.log('hello')
+    }
+}

+ 3 - 0
README.md

@@ -19,6 +19,9 @@
 * 18 set集合
 * 19 map
 * 20 class
+* 21 es6数值的扩展
+* 22 对象的扩展
+* 23 es6模块化 -- 防止命名冲突、代码复用、高维护性
 
 ## 运行说明
     npm i

+ 3 - 0
package.json

@@ -3,6 +3,9 @@
     "start": "http-server -a 127.0.0.1 -p 7070"
   },
   "devDependencies": {
+    "babel-cli": "^6.26.0",
+    "babel-preset-env": "^1.7.0",
+    "browserify": "^17.0.0",
     "http-server": "^0.12.3"
   }
 }