1.特点
构造函数特点:1.函数名大写2.使用this关键字添加属性3.使用new关键字去实例化对象4.this指向实例化的对象
2.例子
// this指实例化的对象 function Student(name,age){ this.name=name; this.age=age; } var meng=new Student("孟阳泽",21) console.log(meng)
3.instanceof 判断一个对象是不是某个类的实例
3-1 array
var arr=[1,2,3]; console.log(arr instanceof Array);//true function Person(name,age){ this.name=name; this.age=age } var p=new Person("mekdf",45); console.log(p instanceof Person)//true
3-2 promise
var p=new Promise((resolve,reject)=>{ resolve(1); reject(2); }) console.log(p instanceof Promise)//true