e 1 anno fa
parent
commit
f583e76820

+ 11 - 0
day23/html/5.判读数据类型.html

@@ -0,0 +1,11 @@
+<!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 src="../js/5.判读数据类型.js"></script>
+</body>
+</html>

+ 11 - 0
day23/html/6.hasOwnProperty.html

@@ -0,0 +1,11 @@
+<!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 src="../js/6.hasOwnProperty.js"></script>
+</body>
+</html>

+ 20 - 0
day23/js/5.判读数据类型.js

@@ -0,0 +1,20 @@
+var a = '123';
+console.log(typeof(a));
+/**
+ * 
+    1.typeOf()
+    2.instanceof:
+    格式:A instanceof B 判断A是否是B的实例对象  true/false 由构造函数类型去判断数据类型
+    3.Object.prototype.toString.call()
+    4.constructor
+ */
+let arr = new Date();
+let fn1 = () => {
+    console.log("函數")
+}
+console.log(fn1 instanceof Function);
+console.log(Object.prototype.toString.call(true))
+let arr1 = [];
+console.log(arr1.constructor == Object)
+let num = '111'
+console.log(num.constructor)

+ 14 - 0
day23/js/6.hasOwnProperty.js

@@ -0,0 +1,14 @@
+// 创建一个构造函数
+function myFn1() {
+
+}
+myFn1.prototype.name = '这是我的名字';
+
+var a1 = new myFn1();
+a1.age = 10;
+// in作用:检查对象中是否含有某个属性值 如果含有返回true 若原型中有也返回true
+console.log("age" in a1);
+console.log("name" in a1);
+// hasOwnProperty()作用:检查对象中是否含有某个属性值 如果本身含有返回true 不含有返回false;若对象本身不含有 原型含有也返回false
+console.log(a1.hasOwnProperty("age"))
+console.log(a1.hasOwnProperty("name"))