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

后端 未结 2 1081
余生分开走
余生分开走 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.

提交回复
热议问题