SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 54 | Next

Jonathan Snook, Aaron Gustafson, Stuart Langridge, and Dan Webb

"Accelerated DOM Scripting with Ajax, APIs, and Libraries"


Functions
Functions are a series of commands wrapped into one call. Functions enable you to encapsulate
code into discrete tasks and enable you to reuse them in different ways (this will be
at the core of Chapter 3 when object-oriented programming with JavaScript is covered).
For example:
function foo(){ } // this is a function
Functions can also be anonymous. This means they don??™t have a name. They??™re like spirits
in the wind. An example is as follows:
function (){ } // this is an anonymous function
CHAPTER 2 n HTML, CSS, AND JAVASCRIPT 21
Anonymous functions are used often in object-oriented JavaScript programming as it
helps you to avoid naming conflicts and enables you to hide code that??™s relevant only to the
object, inside the object.
Functions in JavaScript also have an added perk that you don??™t find in a lot of other mainstream
languages: they are first-class citizens. That means functions can be assigned to
variables and passed as arguments into other functions, returned from functions, and stored
as an element of an array or as a property of an object.
Objects, Properties, and Methods
An object contains variables known as properties and functions known as methods. JavaScript
is very powerful in that it enables you to attach new properties and methods to an object at
any time, even after an object has been instantiated. Functions can actually form the structure
for an object.


Pages:
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
hotel jelenia góra Russian bride Free English grammar and study guid powiekszenia wielkoformatowe counter strike 1.6