Iterate Constructor Chain Up

后端 未结 2 704
旧时难觅i
旧时难觅i 2021-01-21 09:20

Assuming I have something like this:

function A() {}

function B() {}
B.prototype = Object.create(A.prototype);

function C() {}
C.prototype = Object.create(B.pr         


        
2条回答
  •  北恋
    北恋 (楼主)
    2021-01-21 09:44

    Go up the chain using the constructor property of the object's prototype.

    For example, after your code:

     C.prototype.constructor === A
    

    is true, as is

      inst.constructor.prototype.constructor === A
    

    ... and so forth.

提交回复
热议问题