js prototype and __proto__
2017-11-21 14:22:37 0 举报
prototype VS __proto__
作者其他创作
大纲/内容
function / class
null
reference prototype
Object.prototype
reference constructor
function Object
object
when class A
when class B
reference __proto__
class A {}A.idA = 'class A';class B extends A{}B.idB = 'class B extends A';var prototypeOfA = A.prototype;prototypeOfA.idAp = 'A.prototype';var prototypeOfB = B.prototype;prototypeOfB.idBp = 'B.prototype';var instanceOfB = new B();instanceOfB.idBi = 'B.instance';var assert = console.assert;assert(B.__proto__ === A);assert(B.prototype.__proto__ === A.prototype); assert(instanceOfB.__proto__ === B.prototype); assert('idBp' in instanceOfB);assert('idAp' in instanceOfB);assert('idA' in B);
when new B()
function Function
object B.prototype{idBp: 'B.prototype'}
Foo.prototype
function Foo
object A.prototype{idAp: 'A.prototype'}
class B extends Afunction B(){idB: 'class B ext. A'}
instanceof B{idBi: 'instanceof B}
when extends A
class Afunction A(){idA: 'class A'}
Function.prototypefunction f() {...}
0 条评论
下一页