<!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> <!-- 类和对象 -类 es6之前没有class类 构造函数 Person 自有属性 name age 原型定义 sayName 之后所有使用new关键字新建的实例都有拥有这个方法 this.$router.push this.$route.query this.$store --> <script> function Person(name,age){ this.name =name; this.age =age; } Person.prototype.sayName =function(){ console.log(this.name); } Person.prototype.sayAge =function(){ console.log(this.age); } Person.prototype.skill ="vue"; var p =new Person("李四",18); p.sayName(); p.sayAge(); console.log(p.skill); console.log(p.hasOwnProperty("name")); // hasOwnProperty() 判断一个属性是自有的还是公有的 // 构造函数的特点 /* 1 构造函数的首字母大写 2 在函数内部可以通过this关键字,给其添加自有属性 3 可以通过new 关键字实例化一个对象 */ </script></body></html>