Javascript assigning the return value of a Callback function to global variable
<p>I'm new to the community though i've been following Stackoverflow for a long time.</p>

<p>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 properties of the Position object to a global variable at a successful callback it just does not let me do it and the global just remains undefined.</p>

<p>As a workaround to that instead of directly setting the object properties to global variables i'm trying to return it through the callback function but i couldnt find a way to set the return value of the callback function to a global variable.</p>

<p>Here's the simplified code.</p>

<pre><code>var x;

navigator.geolocation.getCurrentPosition(onSuccess, onError);

//on Successful callback receives a Position Object
function onSuccess(position) {  
  var coords = position.coords;  
    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 

}

// onError Callback receives a PositionError object
//
function onError(error) {
    alert('code: '    + error.code    + '\n' +
          'message: ' + error.message + '\n');
}
</code></pre>

<p>This problem is bugging me for a while now.Hope someone can help.Thanks in advance.</p>
