1-1 对象
某一类事物的具体实例
1-2 类
对某一具体事物的抽象
1-3 构造函数
1-3-1 实例
实例: new 出来的对象
1-3-2 构造函数
构造函数:构造一个类(对象)的函数构造函数的特点:1.首字母大写2.函数内部使用this关键字,谁new(实例化)就指向谁3.使用this关键字给对象添加属性4.必须使用new关键字,去生成一个对象
// 在 javascript 中新建一个类 使用构造函数function Student(name,age){ this.name = name; this.age=age}/* this 指实例化的对象 *//* 实例 */var zheng = new Student("zcy",18)console.log(zheng);// 读取对象的属性console.log(p.name);console.log(p.age);
1-3-3 instanceof 判断一个对象是不是某个类的实例
var arr = [1,2,3]console.log(arr instanceof Array); // truefunction Person(name,age){ this.name = name this.age = age}var p = new Person("zheng",18)console.log(p instanceof Person); // true