variable being passed from nowhere to geo location function
I have always had a problem with understanding veriables that get passed from thin air and are not declared anywhere, see the below script for example, i can across it when i was trying to understand the geo location API:
- function geoFindMe() {
- var output = document.getElementById("out");
-
- if (!navigator.geolocation){
- output.innerHTML = "<p>Geolocation is not supported by your browser</p>";
- return;
- }
-
- function success(position) {
- var latitude = position.coords.latitude;
- var longitude = position.coords.longitude;
-
- output.innerHTML = '<p>Latitude is ' + latitude + '° <br>Longitude is ' + longitude + '°</p>';
-
- var img = new Image();
- img.src = "https://maps.googleapis.com/maps/api/staticmap?center=" + latitude + "," + longitude + "&zoom=13&size=300x300&sensor=false";
-
- output.appendChild(img);
- };
-
- function error() {
- output.innerHTML = "Unable to retrieve your location";
- };
-
- output.innerHTML = "<p>Locating…</p>";
-
- navigator.geolocation.getCurrentPosition(success, error);
- }
The above code can be seen HERE.
Now check out this below line:
- function success(position) {
Now who on earth is passing the position variable to success function ? this really baffles me, i have seen similar things when i use jQuery Ajax function. can somebody explain this concept of variables being passed from no-where ?