这个函数的 extern 是什么
我只是无法理解高级模式下的谷歌闭包编译器和相应的外部。
具体:谁能告诉我如何让 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不需要创建 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