fengchuanyu 1 өдөр өмнө
parent
commit
f0bd214ffa

BIN
.DS_Store


+ 80 - 0
8_ES6/18_判断数据类型.html

@@ -0,0 +1,80 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Document</title>
+</head>
+<body>
+    <script>
+        let str = "hello";
+        let num = 10;
+        let bool = true;
+        let und = undefined;
+        let nul = null;
+        let arr = [1,2,3,4,5,6,7,8,9];
+        let obj = {a:10};
+        let fun = function () {
+            console.log("hello");
+        }
+
+        // typeof 运算符
+        // typeof 运算符可以判断一个变量的数据类型
+        // 返回一个字符串 表示数据类型
+        // 一般用作于判断基本数据类型,除了null 和对象返回都是object
+        // console.log(typeof str); // string
+        // console.log(typeof num); // number
+        // console.log(typeof bool); // boolean
+        // console.log(typeof und); // undefined
+        // console.log(typeof nul); // object
+        // console.log(typeof arr); // object
+        // console.log(typeof obj); // object
+
+        // instanceof 运算符
+        // instanceof 运算符可以判断一个对象是否是一个类的实例
+        // 返回一个布尔值
+        // 一般用作于判断引用数据类型 数组 对象 函数
+        // console.log(str instanceof String); // false
+        // console.log(num instanceof Number); // false
+        // console.log(bool instanceof Boolean); // false
+        // console.log(und instanceof undefined); // false
+        // console.log(nul instanceof null); // false
+        // console.log(arr instanceof Array); // true
+        // console.log(obj instanceof Object); // true
+        // console.log(fun instanceof Function); // true
+
+        // constructor 构造函数
+        // constructor 可以判断一个变量的数据类型
+        // 返回一个字符串 表示数据类型
+        // 除了 null 和 undefined 其他都可以使用 constructor 来判断数据类型
+        // console.log(str.constructor); // function String() { [native code] }
+        // console.log(num.constructor); // function Number() { [native code] }
+        // console.log(bool.constructor); // function Boolean() { [native code] }
+        // console.log(und.constructor); // undefined
+        // console.log(nul.constructor); // null
+        // console.log(arr.constructor); // function Array() { [native code] }
+        // console.log(obj.constructor); // function Object() { [native code] }
+        // console.log(fun.constructor); // function Function() { [native code] }
+
+        // 通过 Object.prototype.toString.call() 来判断数据类型
+        // 可以判断所有数据类型
+        // 返回一个带有类型名称的字符串
+        // console.log(Object.prototype.toString.call(str)); // [object String]
+        // console.log(Object.prototype.toString.call(num)); // [object Number]
+        // console.log(Object.prototype.toString.call(bool)); // [object Boolean]
+        // console.log(Object.prototype.toString.call(und)); // [object Undefined]
+        // console.log(Object.prototype.toString.call(nul)); // [object Null]
+        // console.log(Object.prototype.toString.call(arr)); // [object Array]
+        // console.log(Object.prototype.toString.call(obj)); // [object Object]
+        // console.log(Object.prototype.toString.call(fun)); // [object Function]
+
+
+        // 判断数组
+        console.log(Array.isArray(arr))
+
+
+        
+
+    </script>
+</body>
+</html>

+ 33 - 0
8_ES6/19_深拷贝&浅拷贝.html

@@ -0,0 +1,33 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Document</title>
+</head>
+<body>
+    <script>
+        let arr = [1,2,["a","b"],3,4];
+        // let arr2 = arr;
+        let arr2 = [...arr];
+        arr[0]= "a";
+        arr[2][0] = "hello";
+        console.log(arr2);
+
+        let obj = {
+            a:1,
+            b:2,
+            c:{
+                x:100,
+                y:200
+            }
+        }
+        // let obj2 = obj;
+        let obj2 = {...obj};
+        obj.a = 100;
+        obj.c.x = 1000;
+        console.log(obj2);
+        
+    </script>
+</body>
+</html>

+ 37 - 6
8_ES6/练习题3_讲解.html

@@ -117,15 +117,46 @@
 
 
         //9、补全下列代码
-        var o = { prop: 'loveCoding' };
+        // var o = { prop: 'loveCoding' };
 
-        function independent() {
-            return this.prop;
+        // function independent() {
+        //     return this.prop;
+        // }
+        // //在此补全代码
+        // o.f = independent;
+        // console.log(o.f()); //  loveCoding
+
+        //10、用call 或 apply 实现bind 方法
+        function foo(i,j) {
+            console.log(this.a,i,j)
+        }
+        // function fo2(){
+
+        //     console.log(this.a);
+            
+        // }
+        var obj = {
+            a: "hello"
+        }
+
+        // 在函数对象(Function)下添加一个bind2方法
+        Function.prototype.bind2 = function(context){
+            let _this = this;
+            // console.log(arguments);
+            // let arg = Array.from(arguments).slice(1);
+            var arg = Array.prototype.slice.call(arguments,1);
+            // console.log(arg);
+            return function(){
+                // _this.call(context,...arg);
+                _this.apply(context,arg);
+            }
         }
-        //在此补全代码
-        o.f = independent;
-        console.log(o.f()); //  loveCoding
 
+
+        var foo2 = foo.bind2(obj,1,2);
+        // var foo3 = fo2.bind2(obj);
+        foo2()
+        // foo3()
     </script>
 </body>