>> TEACHER: So, in geolocation zero, I declared two functions, one called
geolocate which geolocates the user, and one called call back which was the
function that geolocate called ultimately by way of get current
position once the browser had figured out where the user is.
Now, given that I'm only calling this function once, and it only exists to
be called by get current position, technically, there's no reason that I
had to declare it as a separate function and give it its own name.
Rather, I could have simply implemented an anonymous function,
otherwise known as a lambda function, effectively passing in the code that I
want to be executed after get current position has found the user.
>> In particular, I'd like to have done the following.
First, let's highlight and cut this line of code here in my callback
function so as to use it later.
But let's get rid of the callback function all together.
Now, inside of the geolocate function, let's highlight and delete the name of
the function that I was previously calling, and instead, declare an
anonymous function with no name that still takes an
argument called Position.
And then after this, by convention, let's put an open curly brace.
Down here let's put the closing curly brace and the closing parenthesis and
a semicolon.
>> And then inside of this otherwise anonymous function, let's paste in the
line of code that we'd still like to be called.
Ultimately, then, all I've done is replace a named function with an
anonymous function but have not changed the page's functionality.
But this is arguably a bit cleaner because I'm not littering my code with
unnecessarily defined functions.
Rather, I'm only defining the code I want to be executed exactly where it's
meant to be called.
>> Let's save the file and open the page in a browser.
http://localhost /geolocation1/html And there I still am, in Cambridge,
Massachusetts.
Anonymously.