1.构造函数内部原理
构造函数用new关键字调用时相当于在构造函数内部隐式的执行三步骤:
1.var this={};
2.执行构造函数内部内容
3.return this;
//用new关键字调用时
function Person(name,age){
var this={};
this.name=name;
this.age=age;
return this;
}
//将构造函数就当作函数执行时this其实就指向window
function Person(name,age){
this.name=name;
this.age=age;
}
//用new关键字调用这个构造函数,也会执行最后的return
//如果return的是基础类型值,不会影响隐式的this返回
//如果return的是引用类型值,会覆盖隐式的this
function Person(){
this.name='caiyun';
this,age=3;
return 123;//return {};
}