【JavaScript】new一个对象,其过程中发生了什么?
function Person(){
//隐式1、this = {
}
//2、
this.name = "小明";
this.age = "18";
this.all = function(){
console.log(this.name,this.age);
}
//隐式3、return this;
}
let person = new Person();
其过程中发生的是:
1、在函数体最前面隐式加上this = {};
2、执行this.xxx = xxx;
3、隐式的返回this