-1

How can I execute the function accept in updatePosition ? Why can denyexecute itself but not accept ?

 accept = alert(123);
 deny = alert(123);

 function getLocation(accept,deny) { 
    
    if (navigator.geolocation) {     
        navigator.geolocation.getCurrentPosition(function (position) {
            updatePosition(position, accept);
        }, deny);
    } else {
      deny;
    }

  }

  function updatePosition(position, accept) {
    PositionLat = position.coords.latitude;
    PositionLon = position.coords.longitude;    
    accept;

  }
Helene
  • 3
  • 3

1 Answers1

2

How can I execute the function accept in updatePosition ?

Put () after the name.

Why can denyexecute itself

It can't. You are passing deny as an argument to navigator.geolocation.getCurrentPosition. The code in navigator.geolocation.getCurrentPosition calls it.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335