Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
In Scala, you can define a function inside any scope: in a package, in a class, or even inside another function or method. In the body of a function, you can access any variables from an enclosing scope. That may not sound so remarkable, but note that your function may be called when the variable is no longer in scope.
Here is an example: the mulBy function from Section 12.3, “Functions with Function Parameters,” on page 145.