Preface


JavaScript was originally intended to be a scripting interface between a web page loaded in the browser client (Netscape Navigator at the time), and the application on the server. Since its introduction in 1995, JavaScript has become a key component of web development, and has found uses elsewhere as well.

This book covers the JavaScript language, from its most primitive data types that have been around since the beginnings of the language, to its most complex features, including those involved with Ajax and DHTML. By the end of the book, you will have the basics you need to work with even the most sophisticated libraries and web applications.

Audience

Readers of this book should be familiar with web page technology, including CSS and HTML/XHTML. You may well have seen some JavaScript in that work. Previous programming experience isn't required, though some sections may require extra review if you have no previous exposure to programming.

This book should help:

  • Anyone who wants, or needs, to integrate JavaScript into his own personal web site or sites

  • Anyone who uses a content-management tool, such as a weblogging tool, and wants to better understand the scripting components incorporated into her tool templates

  • Web developers who seek to integrate JavaScript and some of the DHTML/Ajax features into their web sites

  • Web service developers who want to develop for a new market of clients

  • Teachers who use web technologies as either the focus or a component of their courses

  • Web page designers who wish to better understand how their designs can be enlivened with interactive or animated effects

  • Anyone interested in web technologies

Assumptions and Approach

As stated earlier, this book assumes you have experience with (X)HTML and CSS, as well as a general understanding of how web applications work. Programming experience isn't necessary, but the book covers all aspects of JavaScript, some of which are relatively sophisticated. Though the heavier pieces are few, you will need to understand JavaScript enough to work with the newer Ajax libraries.

The book is broken into four sections:

Chapters 1 through 3 provide an introduction to the structure of a JavaScript application, including the simple data types supported in the language, as well as the basic statements and control structures. These establish a baseline of understanding of the language for the sections that follow.

Chapters 4 through 8 introduce the main JavaScript objects, including the all-important function, script access for web-page forms, event handling, scripting security, and working with cookies. Combined, these topics comprise the core of JavaScript, and with these chapters, you can validate form elements, set and retrieve cookies, capture and provide functionality for events, and even create JavaScript libraries. The functionality covered in these chapters has been basic to JavaScript for 10 years, and will remain so for at least another 10.

Chapters 9 through 11 delve into the more sophisticated aspects of web-page development. These chapters cover the Browser Object Model and the newer Document Object Model, and show how you can create your own custom objects. Understanding these models is essential if you wish to create new windows, or individually access, modify, or even dynamically create any page element. In addition, with custom objects, you can then move beyond the capabilities that are prebuilt into either language or browser.

Chapters 12 through 14 get into the advanced uses of JavaScript, including DHTML, Ajax, and some of the many wonderful new libraries that support both.


Chapter 1, Introduction and First Looks

Introduces JavaScript and provides a quick first look at a small web-page application. This chapter also covers some issues associated with the use of JavaScript, including the many tools that are available, as well as issues of security and accessibility.


Chapter 2, JavaScript Data Types and Variables

Provides an overview of the basic data types in JavaScript, as well as an overview of language variables, identifiers, and the structure of a JavaScript statement.


Chapter 3, Operators and Statements

Covers the basic statements of JavaScript, including assignment, conditional, and control statements, as well as the operators necessary for all three.


Chapter 4, The JavaScript Objects

Introduces the first of the built-in JavaScript objects, including Number, String, Boolean, Date, and Math. The chapter also introduces the RegExp object, which provides the facilities to do regular-expression pattern matching. Regular expressions are essential when checking form fields.


Chapter 5, Functions

Focuses on one other JavaScript built-in object, the function. The function is key to creating custom objects, as well as packaging blocks of JavaScript into pieces that can be used, again and again, in many different JavaScript applications. This JavaScript function is relatively simple, but certain aspects can be complex. These include recursion and closure, both of which are introduced in this chapter and detailed in Chapter 11.


Chapter 6, Catching Events

Focuses on event handling, including both the original form of event handling (which is still commonly used in many applications), as well as the newer DOM-based event handling.


Chapter 7, Forms and JiT Validation

Introduces using JavaScript with forms and form fields, including how to access each field typesuch as text input fields and drop-down listsand validate the data once retrieved. Form validation before the form is submitted to the web server helps prevent an unnecessary round trip to the server, and thus saves both time and resource use.


Chapter 8, The Sandbox and Beyond: Cookies, Connectivity, and Piracy

Covers script-based cookies, which store small pieces of data on the client's machine. With cookies, you can store usernames, passwords, and other information so that users don't have to keep reentering data. In addition, since discussion of cookies inevitably leads to discussions of security, the section also covers some security issues associated with JavaScript.


Chapter 9, The Basic Browser Objects

Begins to look at object models accessible from JavaScript, starting with the Browser Object Modela hierarchy of objects including the window, document, forms, history, location, and so on. Through the BOM, JavaScript can open windows; access page elements such as forms, links, and images; and even do some basic dynamic effects.


Chapter 10, DOM: The Document Object Model

Focuses on the Document Object Model, a straightforward, but not trivial, object model that provides access to all document elements and attributes. You'll see documents that are based in XML (such as XHTML) as well as HTML. Though the model is comprehensive and its coverage is fairly straightforward, there could be some challenging moments in the chapter for new programmers.


Chapter 11, Creating Custom JavaScript Objects

Demonstrates how to create custom objects in JavaScript and covers the entire prototype structure that enables such structures in the language. Some programming language concepts are discussed, such as inheritance and encapsulation, but you don't need experience with these concepts.


Chapter 12, Building Dynamic Web Pages: Adding Style to Your Script

Provides a general introduction to some of the more commonly used Dynamic HTML effects, including drag and drop, collapsing and expand page sections, visibility, and movement. Some understanding of CSS is required.


Chapter 13, Moving Outside the Page with Ajax

Introduces Ajax, which, despite all the excitement it has generated, is actually not a complicated use of JavaScript. In addition to covering the components of Ajax, the chapter also provides one example of an application that has promoted Ajax probably more than any other: Google Maps.


Chapter 14, Good News: Juicy Libraries! Amazing Web Services! Fun APIs!

Covers some of the more popular libraries you can download and use for free. This includes Prototype, Sabre's Rico, Dojo, MochiKit, Yahoo! UI, and script.aculo.us. Between these libraries and the book, you'll have all you need to create incredible, and useful, web applications.

Conventions Used in This Book

The following typographical conventions are used in this book:


Italic

Indicates new terms, URLs, email addresses, filenames, and file extensions.


Constant width

Indicates computer code in a broad sense, including commands, arrays, elements, statements, options, switches, variables, attributes, keys, functions, types, classes, namespaces, methods, modules, properties, parameters, values, objects, events, event handlers, XML tags, HTML tags, macros, the contents of files, and the output from commands.


Constant width bold

Shows commands or other text that should be typed literally by the user.


Constant width italic

Shows text that should be replaced with user-supplied values or by values determined by context.

This icon signifies a tip, suggestion, or general note.


This icon indicates a warning or caution.


Web sites and pages are mentioned in this book to help you locate online information that might be useful. Normally both the address (URL) and the name (title, heading) of a page are mentioned. Some addresses are relatively complicated, but you can probably locate the pages easier using your favorite search engine to find a page by its name, typically by writing it inside quotation marks. This may also help if the page cannot be found by its address; it may have moved elsewhere, so the name may still work.

Using Code Examples

This book is here to help you get your job done. In general, you may use the code in this book in your programs and documentation. You do not need to contact us for permission unless you're reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing a CD-ROM of examples from O'Reilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your product's documentation does require permission.

We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: "Learning JavaScript by Shelley Powers. Copyright 2007 O'Reilly Media, Inc., 978-0-596-52746-4."

If you feel your use of code examples falls outside fair use or the permission given above, feel free to contact us at permissions@oreilly.com.

How to Contact Us

Please address comments and questions concerning this book to the publisher:

O'Reilly Media, Inc.
1005 Gravenstein Highway North
Sebastopol, CA 95472
800-998-9938 (in the United States or Canada)
707-829-0515 (international or local)
707-829-0104 (fax)

We have a web page for this book that lists errata, examples, and any additional information. You can access this page at:

http://www.oreilly.com/catalog/learningjvscpt

You can also visit the author's web site for the book at:

http://learningjavascript.info

To comment or ask technical questions about this book, send email to:

bookquestions@oreilly.com

For more information about our books, conferences, Resource Centers, and the O'Reilly Network, see our web site at:

http://www.oreilly.com

Safari® Enabled

When you see a Safari® Enabled icon on the cover of your favorite technology book, that means the book is available online through the O'Reilly Network Safari Bookshelf.

Safari offers a solution that's better than e-books. It's a virtual library that lets you easily search thousands of top tech books, cut and paste code samples, download chapters, and find quick answers when you need the most accurate, current information. Try it for free at http://safari.oreilly.com.

Acknowledgments

With some books, you have a terrific team behind you, and this book is one of those. I want to thank my editor, Simon St.Laurent, for his patience, enthusiasm, and guidance as the book metamorphosed during the writing process. In addition, I want to thank the tech and content reviewers, Steven Champeon, Roy Owens, and Alan Herrell for their excellent suggestions, as well as help in finding the gotchas and rough spots.

I also want to acknowledge Rachel Monaghan, production editor for this book; Mary Anne Weeks Mayo, copyeditor; Johnna VanHoose Dinse, indexer; and Marlowe Shaeffer, production manager.

Finally, I want to send thanks to those who I have met online, in the tech community and out. You were in mind as I wrote the book. In a way, you can say this book was written for youyou know who you are.




Learning JavaScript
Learning JavaScript, 2nd Edition
ISBN: 0596521871
EAN: 2147483647
Year: 2006
Pages: 151

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net