当前位置:首页 > Windows程序 > 正文

在浏览器环境下

2024-03-31 Windows程序

标签:

window or self ?

在 underscore 的判断所处环境的代码中,似乎我们没有看到 window 东西的引用,其实,在浏览器环境下,,self 生存的就是当前 window 东西的引用。那么对对照于使用 window,使用 self 有什么优势呢?我们看到 MDN 上有这么一句话:

The Window.self read-only property returns the window itself, as a WindowProxy. It can be used with dot notation on a window object (that is, window.self) or standalone (self). The advantage of the standalone notation is that a similar notation exists for non-window contexts, such as in Web Workers.

归纳综合来说,就是 self 还能用于一些不具有窗口的上下文环境中,好比 Web Workers。所以,为了处事于更多场景,underscore 选择了越发通用的 self 东西。

!(function(){ var root = (typeof self == "object" && self.self === self && self) || (typeof global == "object" && global.global === global && global) || this; });

  

1.执行环境判断 window 或 self

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/36594.html

Jm-杰米博客Jamie
草根站长的技术交流乐园!IT不会不要紧快来好好学习吧!
  • 20786文章总数
  • 7494592访问次数
  • 建站天数
  • 友情链接