1.特点

  1. 构造函数特点:
  2. 1.函数名大写
  3. 2.使用this关键字添加属性
  4. 3.使用new关键字去实例化对象
  5. 4.this指向实例化的对象

2.例子

  1. // this指实例化的对象
  2. function Student(name,age){
  3. this.name=name;
  4. this.age=age;
  5. }
  6. var meng=new Student("孟阳泽",21)
  7. console.log(meng)

3.instanceof 判断一个对象是不是某个类的实例

3-1 array

  1. var arr=[1,2,3];
  2. console.log(arr instanceof Array);//true
  3. function Person(name,age){
  4. this.name=name;
  5. this.age=age
  6. }
  7. var p=new Person("mekdf",45);
  8. console.log(p instanceof Person)//true

3-2 promise

  1. var p=new Promise((resolve,reject)=>{
  2. resolve(1);
  3. reject(2);
  4. })
  5. console.log(p instanceof Promise)//true