Home  >  Q&A  >  body text

What is the difference between window.window.sessionStorage and sessionStorage?

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?

为情所困为情所困2735 days ago757

reply all(2)I'll reply

  • 仅有的幸福

    仅有的幸福2017-05-19 10:18:49

    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?

    reply
    0
  • 我想大声告诉你

    我想大声告诉你2017-05-19 10:18:49

    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

    reply
    0
  • Cancelreply