构造函数原型内存图-实现继承
2021-09-26 12:07:01 0 举报
俩个不相关的构造函数 实现继承 在内存中的体现
作者其他创作
大纲/内容
GO ={NumberWindowPerson: 0x100Student: 0x500stu: 0x800p: 0x900}
0x600: Student.prototype.__proto__
0x300: Person.prototype.__proto__
0x400: eating
函数
function() { log(this.name + ' studying')}
key
value
__proto__
0x600 0x900
...
内存
0x500: Student
原型链实现继承
scope-chain
GO
Prototype
0x200
代码块
function() { log(this.name + ' eating')}
function Person() { this.name = 'tom'}Person.prototype.eating = function() { log(this.name + ' eating')}function Student() { this.sno = 111}var p = new Person()Student.prototype = pStudent.prototype.studying = function() { log(this.name + ' studying')}var stu = new Student()
0x900: new Person的对象
ECS
0x100: Person
0x101: studying
0x600 0x900
0x101
null
constructor
0x500
0x600
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出栈
0x600: Student.prototype的值
(临时对象obj)-0x800
0x200: Person.prototype
0x400: studying
Person构造this
指向这里的对象
name
tom
收藏
收藏
0 条评论
下一页