以下代码:
(function(local_window) {
local_window.example = 1234;
console.log(window);
console.log(local_window);
}(this));
console.log(this);
console.log(window.example);
console.log(example);
打印(如预期)以下内容:
Window
Window
Window
1234
1234
当:
但是,在Firefox WebExtension内容脚本中,将打印以下内容:
Window
Sandbox { browser: Getter, chrome: Getter, example: 1234, browser: Object, chrome: Object, window: Window → /, document: HTMLDocument → /, location: Location → /, top: Window → /, self: Window → /, 72 more }
Sandbox { browser: Object, chrome: Object, example: 1234, window: Window → /, document: HTMLDocument → /, location: Location → /, top: Window → /, self: Window → /, name: "", history: History, 72 more }
undefined
1234
example !== window.example
是一个非常奇怪的惊喜,然后将Chrome扩展移植到FF。这是一个意图破坏(或错误)?这记录在哪里?我在MDN compatibility notes中看不到它。
上下文:我在内容脚本中使用zepto.js(将其自身安装到this.$
中)并且一段代码使用window.$
访问它,但在FF上失败。
答案 0 :(得分:1)
答案 1 :(得分:0)
我同意此行为与Firefox的文档和兼容性问题背道而驰,因此我提交了:https://bugzilla.mozilla.org/show_bug.cgi?id=1607242