I am trying to include a generated js module in my webpage.(我正在尝试在网页中包含一个生成的js模块。)
Yet it gives me an error: Uncaught TypeError: Cannot read property 'Object' of undefined
at $g["Object"]["freeze"]($env);
(但是它给了我一个错误: Uncaught TypeError: Cannot read property 'Object' of undefined
$g["Object"]["freeze"]($env);
Uncaught TypeError: Cannot read property 'Object' of undefined
$g["Object"]["freeze"]($env);
)
The minimal example is:(最小的示例是:)
File index.html
:(文件index.html
:)
<html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type"/>
</head>
<body>
<!-- Note the usage of `type=module` here as this is an ES6 module -->
<script type="module">
import { foo } from './foo.js';
console.log(foo());
</script>
</body>
</html>
File foo.js
:(文件foo.js
:)
'use strict';
/* Scala.js runtime support
* Copyright 2013 LAMP/EPFL
* Author: Sébastien Doeraene
*/
/* ---------------------------------- *
* The top-level Scala.js environment *
* ---------------------------------- */
// Get the environment info
var $env = (typeof __ScalaJSEnv === "object" && __ScalaJSEnv) ? __ScalaJSEnv : {};
// Global scope
var $g =
(typeof $env["global"] === "object" && $env["global"])
? $env["global"]
: ((typeof global === "object" && global && global["Object"] === Object) ? global : this);
$env["global"] = $g;
$env["exportsNamespace"] = void 0;
// Freeze the environment info
$g["Object"]["freeze"]($env);
export function foo() { return "Hello"; }
But if I just copy paste the script into chrome console, then everything works as it should.(但是,如果我只是将脚本复制粘贴到chrome控制台中,那么一切都会正常进行。)
ask by Ford O. translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…