Javascript assigning the return value of a Callback function to global variable

后端 未结 5 1346
北海茫月
北海茫月 2020-12-28 19:01

My question is about Javascript. I have a Callback function which receives a Position object on a successful callback.

The problem is that when I try to set the prop

5条回答
  •  南笙
    南笙 (楼主)
    2020-12-28 19:21

    have you tried setting it via the global window object?

    //on Successful callback receives a Position Object
    function onSuccess(position) {  
      var coords = position.coords;  
        window.x=coords;       // Setting directly to an object does not work x still remains undefined after succesful callback               
    return coord; // Trying to set this to a global object 
    
    }
    

    also, since you return the coordinates from the success handler, is there not another way to get this value?

提交回复
热议问题