如果您将一个 documentFragment 附加到一个元素,然后您从该元素中清除了附加的节点,那么您的 documentFragment 也将是空的并且不能再被重用!附加您的 documentFragment 的克隆可以防止这种情况,并允许您的 documentFragment 多次重用。
我假设 jsperf 片段的作者正在测试这种情况。
Example: dropdowns with a parent-child relationship. Lets say you have a dropdown where you select a continent, and a second dropdown that lists all the countries in that continent. If you want to cache the created documentFragments with the option nodes after creation, using cloneNode is necessary. Imagine someone selects europe, then africa, then europe again: you can either recreate the entire documentfragment, of cache it.
I created a jsperf snippet to illustrate the performance difference of recreating the documentFragments vs caching and cloning the fragments:
http://jsperf.com/documentfragment-cache-vs-recreate