构造函数原型内存图
2021-09-26 09:24:30 0 举报
俩个不相关的构造函数 在内存中的体现
作者其他创作
大纲/内容
GO ={NumberWindowPerson: 0x100Student: ox500stu: ox800}
function Person() { this.name = 'why'}Person.prototype.eating = function() { log(this.name + ' eating')}function Student() { this.sno = 111}Student.prototype.studying = function() { log(this.name + ' studying')}var stu = new Student()
0x600: Student.prototype.__proto__
key
value
scope-chain
GO
Prototype
0x600
代码块
...
0x300: Person.prototype.__proto__
0x400: eating
__proto__
null
函数
function() { log(this.name + ' studying')}
constructor
ox500
studying
0x700
GEC
VO: GO this
执行:new Student() stu = new Student()
ox100
0x300
eating
0x400
FEC: Student AO
VO: GO+scope this
执行: 1.构造函数St内部创建一个临时对象obj 2.obj.__proto__ = St.prototype 3.St内部this 绑定到obj 4.执行St内部代码 5.返回obj: ox800----AO出栈
ox600
0x600: Student.prototype
内存
(临时对象obj)-ox800
0x200: Person.prototype
0x500: Student
0x200
function() { log(this.name + ' eating')}
0x400: studying
ECS
0x100: Person
收藏
收藏
0 条评论
下一页