Open Twlig opened 2 years ago
要创建 Person 的新实例,必须使用 new 操作符。
var obj = new Person();
new的过程中经历以下4个步骤:
(1) 创建一个空对象
obj = new Object();
(2)设置原型链
obj.__proto__ = Person.prototype;
(3)让Person中的this指向obj,并执行Person函数体
Person.call(obj);
(4) 返回新对象
要创建 Person 的新实例,必须使用 new 操作符。
new的过程中经历以下4个步骤:
(1) 创建一个空对象
(2)设置原型链
(3)让Person中的this指向obj,并执行Person函数体
(4) 返回新对象