js中new一个对象的过程

  1. 创建一个空对象  varobj = newObject();
  2. 让Person中的this指向新创建的空对象obj,并执行Person的函数体   varresult = Person.call(obj);
  3. 执行代码,即对this赋值    obj.__proto__ = Person.prototype;
  4. 返回this
1  function Person(name, age) {
2     this.name = name;
3     this.age = age;
   // return this (默认有这一行返回this对象)
4  } 5  var person = new Person("Alice", 23);
原文地址:https://www.cnblogs.com/chailuG/p/11259530.html