gpt4 book ai didi

javascript - 从 Javascript 中的嵌套函数返回值

转载 作者:IT王子 更新时间:2023-10-29 02:57:53 25 4
gpt4 key购买 nike

<分区>

我有一个函数,设置如下

function mainFunction() {
function subFunction() {
var str = "foo";
return str;
}
}

var test = mainFunction();
alert(test);

按照我的逻辑,该警报应返回“foo”,但它返回未定义。我做错了什么?

更新:这是我的实际代码(这是一个使用 Google API 进行反向地理编码的函数)

function reverseGeocode(latitude,longitude){
var address = "";
var country = "";
var countrycode = "";
var locality = "";

var geocoder = new GClientGeocoder();
var latlng = new GLatLng(latitude, longitude);

return geocoder.getLocations(latlng, function(addresses) {
address = addresses.Placemark[0].address;
country = addresses.Placemark[0].AddressDetails.Country.CountryName;
countrycode = addresses.Placemark[0].AddressDetails.Country.CountryNameCode;
locality = addresses.Placemark[0].AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.LocalityName;
return country;
});
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com