Why use chained prototype inheritance in javascript?

后端 未结 3 1107
礼貌的吻别
礼貌的吻别 2021-02-08 10:05

perf

Why do we build a prototype inheritance chain rather then using object composition. Looking up through the prototype for each step in the chain get\'s expensive.

3条回答
  •  生来不讨喜
    2021-02-08 10:36

    Well, consider what would happen if lower or upper changed. The combined prototype wouldn't reflect that change since you've created a new object by copying properties from them.

    For many situations that would be fine, but it's sure not as dynamic as actually constructing proper prototype chains for your objects.

提交回复
热议问题