[英]Why is an existing JavaScript function not found generating Uncaught ReferenceError
The error:错误:
readyException.js:6 Uncaught ReferenceError: editMap is not defined
at HTMLDocument.<anonymous> (edit:190)
at mightThrow (deferred.js:97)
at process (deferred.js:139)
The page from Chrome Source ( popupText
is generated with Rails):来自 Chrome 源的页面( popupText
是用 Rails 生成的):
<div id="map"></div>
<script>
var popupText = "≥1908<br>Benefit St<br>≤1908<br>Fountain Ave";
$(document).ready(function() {
editMap(popupText);
});
</script>
A few relevant lines of application.js
from Chrome Sources来自 Chrome Sources 的一些相关的application.js
行
function editMap(popupText) {
if (laMap != undefined) {
laMap.remove();
}
showMap(popupText)
var drawnItems = new L.FeatureGroup();
Trying to move an app to Rails 6 and webpacker.试图将应用程序移动到 Rails 6 和 webpacker。
Webpack does not expose your JavaScript to the global scope; Webpack 不会将您的 JavaScript 暴露给全局 scope; every file is treated as a module, which, in practice, is a function with its own scope.每个文件都被视为一个模块,在实践中,它是一个带有自己的 scope 的 function。 To expose a particular reference to the global scope, you can assign it to the window
object, eg, window.editMap = editMap
, from within the module.要公开对全局 scope 的特定引用,您可以将其分配给window
object,例如, window.editMap = editMap
模块中的 Z05B8C74CBD97025FBF2DEZC1A
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.