What is the difference between window.window.sessionStorage and sessionStorage?
为情所困
为情所困 2017-05-19 10:16:49
0
2
725

I saw someone else writing in a vue project:

  // 如果从详情返回并且之前存有对应的查询条件和参数
            // 则直接渲染之前的数据
            if (window.window.sessionStorage.searchKey && window.window.sessionStorage.tab === this.searchKey.tab) {
                this.topics = JSON.parse(window.window.sessionStorage.topics);
                this.searchKey = JSON.parse(window.window.sessionStorage.searchKey);
            //  下一个dom 更新序列之后再执行函数
                this.$nextTick(
                  () => $(window).scrollTop(window.window.sessionStorage.scrollTop)
                );
            } else {
                this.getTopics();
            }

Why does window.window.sessionStorage here add two windows?
It stands to reason that the result of window.window.sessionStorage=== window.sessionStorage is true. What considerations does the author have in writing this?

w3c says this:

The window.window property is equivalent to the self property, which contains a reference to the window itself.

window.window What other application scenarios are there for writing like this?

为情所困
为情所困

reply all(2)
仅有的幸福

Writing like this doesn’t seem to make sense, right? The window is originally under the window, so what’s the point of adding one more?

我想大声告诉你

From this, I don’t think there is any difference.


The reason why there is window.window This approach should be to avoid:

Personal opinion

JavaScript 的垃圾回收 GC It is possible to recycle the window object, so I did this.

A statement from Baozhan

(The bottom one) Stackoverflow - window.window in JavaScript

MDN explanation

The window property of a window object points to the window object itself

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!