Javascript Sencha Touch-can';无法从其他函数获取值

Javascript Sencha Touch-can';无法从其他函数获取值,javascript,extjs,geolocation,sencha-touch-2,Javascript,Extjs,Geolocation,Sencha Touch 2,我有两个函数,我想从一个函数调用另一个函数,得到两个值 renderMap: function(){ // here I need to call getCurrentLocation function and get 2 values - lat and lng from it. console.log(lat, lng); }, getCurrentLocation: function() { var me = this, lat,

我有两个函数,我想从一个函数调用另一个函数,得到两个值

renderMap: function(){
    // here I need to call getCurrentLocation function and get 2 values - lat and lng from it.
    console.log(lat, lng);
},

getCurrentLocation: function() {
    var me = this,
        lat,
        lng;

    Ext.device.Geolocation.getCurrentPosition({     
        success: function(position) {
            me.lat = position.coords.latitude;
            me.lng = position.coords.longitude;
        }
    });
},

请建议如何正确执行此操作。

您可以从getCurrentLocation返回对象,例如:

return {lat:xxxx, lng:yyyy};

调用
Ext.device.Geolocation.getCurrentPosition
时,
me
不再存在

到那时,您已处于不同的上下文或范围,
Ext.device.Geolocation
类对
me
变量一无所知

在方法开始时,它引用了控制器,但随后调用了
Ext.device.Geolocation
类的
getCurrentPosition
方法,因为您没有将任何参数传递给方法
me
应该是
未定义的

它认为你可以用Ext.bind解决这个问题

还可以在JavaScript中查找调用和应用:)


向@code4jhon问好

还有一件事要说。设备调用是异步的,这意味着
getCurrentLocation
不返回位置数据。它只初始化设备请求并立即返回。已知位置数据后,将调用函数
success
,以便您可以从中调用
renderMap