new的执行过程
1、在内存中创建了一个空的对象
2、让构造函数中的this指向刚刚创建的对象
3、执行构造数,在构造函数中设置属性和方法
4、返回了当前对象函
//Student自定义构造函数
function Student(name,age){
console.log(this);
//属性
this.age=age;
this.name=name;
//方法
this.sayHi=function(){
console.log(this.name+':hello');
}
console.log(this);
}
var stu1=new Student('lisi',13);
console.log(stu1);
stu1.sayHi();