Why is the Temp.prototype on the MDN Object.create polyfill set to null?

后端 未结 2 1077
余生分开走
余生分开走 2021-01-07 04:10

Why does the MDN polyfill for Object.create have the following line:

Temp.prototype = null;

Is it so that we avoid maintaining a reference

相关标签:
2条回答
  • 2021-01-07 04:59

    Yes, exactly. This polyfill does hold the Temp function forever in memory (so that its faster on average, not needing to create a function for every invocation of create), and resetting the .prototype on it is necessary so that it does not leak.

    0 讨论(0)
  • 2021-01-07 05:00

    I think this is just clean, Temp.prototype is kind of static, since it is set before new Temp() it is nice to clean it after.

    0 讨论(0)
提交回复
热议问题