Beginning AngularJS

(WallPaper) #1

ChApter 1 ■ JAvASCrIpt You Need to KNow


Listing 1-31. Storing a Function Reference in a Variable: Part 2


<!DOCTYPE html>




JavaScript Primer





Listing 1-31 defines a function and stores a reference to that function in two separate steps. This time around, the
function has a name. We can use both its name and the reference to call it. The following output confirms this.


callbacks part 2
callbacks part 2
callbacks part 2
callbacks part 2
callbacks part 2


Keeping in mind the idea of functions as values that can be assigned to variables, we now look at callbacks.
Callbacks are just functions that you pass to some other function, so that they can be called at some later point. The
reasons you might want to do this may vary, but it is generally due to some circumstance for which you must wait
some time before your function has enough context to execute meaningfully, such as with Ajax calls to a web server.


■ Note Ajax allows web pages to be updated asynchronously by exchanging small amounts of data with the server


behind the scenes. this makes it possible to update parts of a web page without reloading the whole page. one of the


ways AngularJS supports this is through its $http service, which we will see more of in Chapter 7.

Free download pdf