peachpit press the javascript pocket guide (2010)

312 545 0
peachpit press the javascript pocket guide (2010)

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

[...]... into the next line */ xxii The JavaScript Pocket Guide Semicolons JavaScript statements should end with semicolon like sentences end with a period Technically they are optional, but that’s only because JavaScript interpreters add them automatically at the end of most lines It’s best to get into the habit of adding the semicolons yourself because there can be strange side effects when you let the interpreter... produce expressive and powerful code, but it also creates the potential for ambiguity and confusion Symbols in the language combine to create syntax, which acts as the structure or grammar of the language Values, variables, and functions are the subjects and actions 2 The JavaScript Pocket Guide Once you get the hang of the symbols and syntax, learning JavaScript is a matter of understanding the various... Association (ECMA), which published the fifth edition of the language in December 2009 xviii The JavaScript Pocket Guide JavaScript is a scripting language, meaning it gives you the ability to control an environment with code In the case of JavaScript, the environment is usually a Web page in a browser, where you can react to the mouse and keyboard, create and animate elements on the page, communicate with... into the bottom of the Console tab and hit Enter/Return to execute the code To type multiple lines at once, expand the text box by clicking the arrow on the right (Figure I.2) In this book, the regular code in the examples demonstrates what you enter into Firebug, and the highlighted code gives you an example of the result (The function console.log() is another way to print output to the console; I’ll... get the hang of it, though, plenty of books and online resources are available to help you write efficient JavaScript code You can find all of the code examples from the tutorial chapters of this book, as well as a few bonus chapters, on its companion Web site http://www .peachpit. com/javascriptpocketguide Resources While you’re online, here are two of my favorite JavaScript resources on the Web for further... more Why JavaScript Is Cool The following are the reasons why JavaScript is cool—or at least why I think it’s cool: I Low barrier to entry Anyone can start writing and testing JavaScript code with software they already have on their computer I Easy of deployment All you need to include JavaScript on your Web site is a server to store the code files and the tag I Small language, big power The language... built-in JavaScript console if you prefer to use a browser other than Firefox I find Firebug’s output to be the most useful, however, so the example output printed in this book may not match what you see if you use another browser Now that you have the Firebug extension for Firefox set up (or are using another browser), you’re ready to write some JavaScript code 1 JavaScript Basics A lot of people learn JavaScript. .. tasks Throughout the chapters and code examples, I emphasize the important concepts more than the minute details, but you’ll also be able to take much of this code and use it in your own sites right away xx The JavaScript Pocket Guide What’s Not in This Book I’m not trying to cover everything about JavaScript Some parts of the scripting language are problematic and not worth using Other parts are used... Single-line text box Firebug icon Figure I.2 The multiline text box in Firebug Button to switch between single-line and multiline text box xxvi The JavaScript Pocket Guide You may need to “enable” the console (Figure I.3) and refresh the Web page The console doesn’t work unless you’ve visited a page first, so I usually load Google.com t ip Figure I.3 Enabling the console Most modern browsers—including... snippet of JavaScript and quickly see the result I’ll use Firebug to demonstrate how JavaScript works throughout most of the book, so to follow along with the examples, you’ll want to download and install it (http://getfirebug.com) After you install Firebug, load up a Web page and click the Firebug icon (Figure I.1) in the lower-right corner of Firefox You type singleline JavaScript statements into the bottom . class="bi x0 y0 w0 h1" alt="" The JavaScript PocketGuide LennyBurdette Ginormous knowledge, pocket- sized. The JavaScript Pocket Guide Lenny Burdette Peachpit Press 1249 Eighth Street Berkeley,. (ECMA), which published the fifth edition of the language in December 2009. Introduction The JavaScript Pocket Guidexviii JavaScript is a scripting language, meaning it gives you the ability to control. Bruce Hyslop for the opportunity to write this book as well the faith that I could. Huge thanks go to editor Kim Wimpsett and the rest of the team at Peachpit Press for making the process go

Ngày đăng: 28/04/2014, 16:53

Mục lục

  • Introduction

    • Why JavaScript Is Cool

    • Who Should Read This Book

    • What You Need to Follow Along

    • What’s in This Book

    • What’s Not in This Book

    • Writing JavaScript Code

      • Case Sensitivity

      • Whitespace and New Lines

      • Balanced Brackets and Quotes

      • Chapter 1: JavaScript Basics

        • Expressions and Statements

        • Control Flow

          • if/if-else/else

          • Logical AND: &&

          • Constants and Functions

            • The Math Object

            • Even More Properties and Methods

            • Methods

              • Changing Case: toUpperCase(), toLowerCase()

              • Extracting Parts of a String

                • charAt(x), charCodeAt(x)

                • Converting Strings to Arrays: split([delimiter, limit])

                • Search and Replace

                  • indexOf(substring[, start])

                  • Global Functions

                    • escape(string), unescape(string)

                    • encodeURI(string), decodeURI(string)

                    • encodeURIComponent(string), decodeURIComponent(string)

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan