1
0
mirror of https://github.com/ruanyf/es6tutorial.git synced 2025-05-25 19:22:21 +00:00

word change.

This commit is contained in:
favefan 2018-06-21 09:28:48 +08:00 committed by GitHub
parent 06fac98bb1
commit e4351e2a70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -591,7 +591,7 @@ ES5 的顶层对象,本身也是一个问题,因为它在各种实现里面
- 全局环境中,`this`会返回顶层对象。但是Node 模块和 ES6 模块中,`this`返回的是当前模块。
- 函数里面的`this`,如果函数不是作为对象的方法运行,而是单纯作为函数运行,`this`会指向顶层对象。但是,严格模式下,这时`this`会返回`undefined`
- 不管是严格模式,还是普通模式,`new Function('return this')()`,总是会返回全局对象。但是,如果浏览器用了 CSPContent Security Policy内容安全策),那么`eval``new Function`这些方法都可能无法使用。
- 不管是严格模式,还是普通模式,`new Function('return this')()`,总是会返回全局对象。但是,如果浏览器用了 CSPContent Security Policy内容安全策),那么`eval``new Function`这些方法都可能无法使用。
综上所述,很难找到一种方法,可以在所有情况下,都取到顶层对象。下面是两种勉强可以使用的方法。