我的Electron应用在app.on("ready",
之后加载index.html,但是script标签中的this
并未按预期指向Window对象。知道为什么吗?
如果我使用console.log(Window),则该对象确实存在并打印出来
global {frames: global, postMessage: ƒ, blur: ƒ, focus: ƒ, close: ƒ, …}
main.js ...加载index.html
app.on("ready", function () {
mainWindow = new BrowserWindow({
width: 1400,
height: 2000,
webPreferences: {
nodeIntegration: true
},
},
mainWindow.loadURL("file://" + __dirname + "/index.html");
}
index.html ...'this'未定义
<script src="elm.js"></script>
<script>
console.log(this) // This returns 'undefined'
var app = Elm.Main.init({
node: document.getElementById('elm')
});
</script>
elm.js ....将未定义的'this'传递给导致错误的函数
(function(scope){
'use strict';
--- omitted ----
var author$project$Main$main = elm$browser$Browser$sandbox(
{init: author$project$Main$init, update: author$project$Main$update, view: author$project$Main$view});
_Platform_export({'Main':{'init':author$project$Main$main(
elm$json$Json$Decode$succeed(_Utils_Tuple0))(0)}});}(this));