这个函数的 extern 是什么

发布于 2025-01-05 22:08:13 字数 1095 浏览 1 评论 0原文

我只是无法理解高级模式下的谷歌闭包编译器和相应的外部。

具体:谁能告诉我如何让 CC 处于高级模式而不重命名此函数,因为我需要从 HTML 中调用它 () ?

function searchAddress() {

    geocoder = new google.maps.Geocoder();
    var useraddress = $('#where').val();

    if (geocoder && useraddress) {   
        geocoder.geocode( {'address': useraddress, 'region': region}, function(results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                myPosition = results[0].geometry.location;
                myAccuracy = 150;
                echoAddress(results[0].formatted_address);
            }
        });
    }
}

我以为我明白我需要编写一个 extern 文件,因为该函数是从外部代码调用的,传递类似

window['searchAddress'] = searchAddress

or 的

function searchAddress() {}

东西,但这些和其他几个尝试都不起作用。 CC编译没有错误,但浏览器抱怨

未捕获的异常:ReferenceError:未定义的变量:searchAddress

searchAddress()已被CC删除,不再是我的min.js中的函数名称。感谢您的任何提示。感谢解释,谢谢。

I just don't get to understand the google closure compiler in advanced mode and the respective extern.

Concrete: can anybody tell me how to keep CC in advanced mode from renaming this function since I need to call it from my HTML (<a href="javascript:searchAddress();">)?

function searchAddress() {

    geocoder = new google.maps.Geocoder();
    var useraddress = $('#where').val();

    if (geocoder && useraddress) {   
        geocoder.geocode( {'address': useraddress, 'region': region}, function(results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                myPosition = results[0].geometry.location;
                myAccuracy = 150;
                echoAddress(results[0].formatted_address);
            }
        });
    }
}

I thought I understood I need to write an extern file since the function is being called from external code, passing something like

window['searchAddress'] = searchAddress

or

function searchAddress() {}

but none of these and several other tries work. CC compiles without error, but the browser complains

Uncaught exception: ReferenceError: Undefined variable: searchAddress

searchAddress() has been deleted by CC and is not a function name in my min.js anymore. Thanks for any hint. Explanations appreciated, thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鹿港巷口少年归 2025-01-12 22:08:13

您不需要创建 extern,您想要导出函数:

http://code.google.com/closure/compiler/docs/api-tutorial3.html

将其添加到代码中(不是外部文件):

window['searchAddress'] = searchAddress

You don't need to create an extern, you want to export the function:

http://code.google.com/closure/compiler/docs/api-tutorial3.html

Add this to the code (not an extern file):

window['searchAddress'] = searchAddress

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文