|
@@ -0,0 +1,46 @@
|
|
|
|
|
+<!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>
|
|
|
|
|
+ // 普通函数
|
|
|
|
|
+ // function fn() {
|
|
|
|
|
+ // return 5;
|
|
|
|
|
+ // };
|
|
|
|
|
+ // console.log(fn())
|
|
|
|
|
+ // // 匿名函数
|
|
|
|
|
+ // let fn1 = function() {}
|
|
|
|
|
+ // // 立即执行函数
|
|
|
|
|
+ // (function() {})();
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 构造函数
|
|
|
|
|
+ * 1.首字母大写
|
|
|
|
|
+ * 2.new进行实例化调用
|
|
|
|
|
+ * 3.this指向当前实例
|
|
|
|
|
+ * 4.不用return进行反值
|
|
|
|
|
+ * 属性写在构造函数中
|
|
|
|
|
+ * 方法写在原型中
|
|
|
|
|
+ * 构造函数中自带了prototype属性 指向的是当前构造函数的原型
|
|
|
|
|
+ */
|
|
|
|
|
+ function Fn() {
|
|
|
|
|
+ // console.log(this)
|
|
|
|
|
+ this.name = '图图';
|
|
|
|
|
+ this.age = 3;
|
|
|
|
|
+ Fn.prototype.address = function () {
|
|
|
|
|
+ console.log("我家住在翻斗花园");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ // 实例化调用
|
|
|
|
|
+ let f = new Fn();
|
|
|
|
|
+ console.log(f);
|
|
|
|
|
+ f.address();
|
|
|
|
|
+ </script>
|
|
|
|
|
+</body>
|
|
|
|
|
+
|
|
|
|
|
+</html>
|