diff options
| author | t7yang <t7yang@gmail.com> | 2021-07-17 16:10:02 +0800 |
|---|---|---|
| committer | Irvin <irvinfly@gmail.com> | 2021-07-19 23:04:27 +0800 |
| commit | a02f4b2f60c81e09b318a090e5c9c2d2d641c878 (patch) | |
| tree | 2b1849e7a34cb367ff6624e35a35fc827eceef6b /files/zh-cn/web/javascript/reference/global_objects/globalthis/index.html | |
| parent | 8af4d5e8a260f3474b4273d573532ec6fec08ab4 (diff) | |
| download | translated-content-a02f4b2f60c81e09b318a090e5c9c2d2d641c878.tar.gz translated-content-a02f4b2f60c81e09b318a090e5c9c2d2d641c878.tar.bz2 translated-content-a02f4b2f60c81e09b318a090e5c9c2d2d641c878.zip | |
replace wiki links in zh-CN
Diffstat (limited to 'files/zh-cn/web/javascript/reference/global_objects/globalthis/index.html')
| -rw-r--r-- | files/zh-cn/web/javascript/reference/global_objects/globalthis/index.html | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/files/zh-cn/web/javascript/reference/global_objects/globalthis/index.html b/files/zh-cn/web/javascript/reference/global_objects/globalthis/index.html index 20b6dba280..7260d8cbfa 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/globalthis/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/globalthis/index.html @@ -30,7 +30,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/globalThis <p>在以前,从不同的 JavaScript 环境中获取全局对象需要不同的语句。在 Web 中,可以通过 <code>window</code>、<code>self</code> 或者 <code>frames</code> 取到全局对象,但是在 <a href="/zh-CN/docs/Web/API/Worker">Web Workers</a> 中,只有 <code>self</code> 可以。在 Node.js 中,它们都无法获取,必须使用 <code>global</code>。</p> -<p>在松散模式下,可以在函数中返回 <code>this</code> 来获取全局对象,但是在严格模式和模块环境下,<code>this</code> 会返回 <code>undefined</code>。 You can also use <code>Function('return this')()</code>, but environments that disable {{jsxref("eval", "eval()")}}, like <a href="https://wiki.developer.mozilla.org/en-US/docs/Glossary/CSP">CSP</a> in browsers, prevent use of {{jsxref("Function")}} in this way.</p> +<p>在松散模式下,可以在函数中返回 <code>this</code> 来获取全局对象,但是在严格模式和模块环境下,<code>this</code> 会返回 <code>undefined</code>。 You can also use <code>Function('return this')()</code>, but environments that disable {{jsxref("eval", "eval()")}}, like <a href="/zh-CN/docs/Glossary/CSP">CSP</a> in browsers, prevent use of {{jsxref("Function")}} in this way.</p> <p><code>globalThis</code> 提供了一个标准的方式来获取不同环境下的全局 <code>this</code> 对象(也就是全局对象自身)。不像 <code>window</code> 或者 <code>self</code> 这些属性,它确保可以在有无窗口的各种环境下正常工作。所以,你可以安心的使用 <code>globalThis</code>,不必担心它的运行环境。为便于记忆,你只需要记住,全局作用域中的 <code>this</code> 就是 <code>globalThis</code>。</p> |
