Is there any difference between: window.localStorage and localStorage?

后端 未结 5 557
执笔经年
执笔经年 2021-01-07 17:46

I have been doing the following:

var store = window.localStorage;
store.setItem()

but now I see code doing this:

localStora         


        
5条回答
  •  伪装坚强ぢ
    2021-01-07 18:41

    Supposedly, window.localStorage makes the localStorage faster to be found than just writing localStorage.

    Storing a reference to it on a variable makes it even faster.

    Anyway, these improvements are negligible on modern browsers. It only becomes useful if performance is being an issue.
    Anyway, you get a possible idea about why it is being done like that.

提交回复
热议问题