Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
new constructor的过程
1. 创建一个新的对象,这个对象的类型是object。
2. 该对象的prototype设置为构造器的prototype属性,即this.prototype = Foo.prototype (伪代码)
3. 执行构造器函数。
4. 如果构造器函数有返回值,则以该对象作为返回值。若没有return或return了基本类型,则将上述的新对象作为返回值。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment