1. Trang chủ
  2. » Công Nghệ Thông Tin

Secrets of the JavaScript Ninja pdf

364 1.3K 3

Đ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

Cấu trúc

  • Secrets of the JavaScript Ninja MEAP v10

  • Copyright

  • Table of Contents

  • Chapter 1: Enter the ninja

    • 1.1 Our key JavaScript libraries

    • 1.2 Understanding the JavaScript Language

    • 1.3 Cross-browser considerations

    • 1.4 Best practices

      • 1.4.1 Best practice: testing

      • 1.4.2 Best practice: performance analysis

    • 1.5 Summary

  • Chapter 2: Testing and debugging

    • Debugging Code

      • 2.1.1 Logging

      • 2.1.2 Breakpoints

    • 2.2 Test generation

    • 2.3 Testing frameworks

      • 2.3.1 QUnit

      • 2.3.2 YUITest

      • 2.3.3 JSUnit

    • 2.4 The Fundamentals of a Test Suite

      • 2.4.1 The assertion

      • 2.4.2 Test groups

      • 2.4.3 Asynchronous Testing

    • 2.5 Summary

  • Chapter 3: Functions are fundamental

    • 3.1 What’s with the functional difference?

      • 3.1.1 Why is JavaScript’s functional nature important?

      • 3.1.2 Sorting with a comparator

    • 3.2 Declarations

      • 3.2.1 Scoping and functions

    • 3.3 Invocations

      • 3.3.1 From arguments to function parameters

      • 3.3.2 Invocation as a function

      • 3.3.3 Invocation as a method

      • 3.3.4 Invocation as a constructor

      • 3.3.5 Invocation with the apply and call methods

    • 3.4 Summary

  • Chapter 4: Wielding functions

    • 4.1 Anonymous functions

    • 4.2 Recursion

      • 4.2.1 Recursion in named functions

      • 4.2.2 Recursion with object methods

      • 4.2.3 The pilfered reference problem

      • 4.2.4 Inline named functions

      • 4.2.5 The callee property

    • 4.3 Fun with function as objects

      • 4.3.1 Storing functions

      • 4.3.2 Self-memoizing functions

      • 4.3.3 Faking array methods

    • 4.4 Variable-length argument lists

      • 4.4.1 Using apply() to supply variable arguments

      • 4.4.2 Function overloading

    • 4.5 Checking for functions

    • 4.6 Summary

  • Chapter 5: Closing in on closures

    • 5.1 How closures work

    • 5.2 Putting closures to work

      • 5.2.1 Private variables

      • 5.2.2 Callbacks and timers

    • 5.3 Binding function contexts

    • 5.4 Partially applying functions

    • 5.5 Overriding function behavior

      • 5.5.1 Memoization

      • 5.5.2 Function wrapping

    • 5.6 Immediate functions

      • 5.6.1 Temporary scope and private variables

      • 5.6.2 Loops

      • 5.6.3 Library wrapping

    • 5.7 Summary

  • Chapter 6: Object-orientation with prototypes

    • 6.1 Instantiation and prototypes

      • 6.1.1 Object instantiation

      • 6.1.2 Object typing via constructors

      • 6.1.3 Inheritance and the prototype chain

      • 6.1.4 HTML DOM prototypes

    • 6.2 The Gotchas!

      • 6.2.1 Extending Object

      • 6.2.2 Extending Number

      • 6.2.3 Subclassing native objects

      • 6.2.4 Instantiation issues

    • 6.3 Writing class-like code

      • 6.3.1 Checking for function serializability

      • 6.3.2 Initialization of subclasses

      • 6.3.3 Preserving super methods

    • 6.4 Summary

  • Chapter 7: Wrangling regular expressions

    • 7.1 Why regular expressions rock

    • 7.2 A regular expression refresher

      • 7.2.1 Regular expressions explained

      • 7.2.2 Terms and operators

    • 7.3 Compiling regular expressions

    • 7.4 Capturing matching segments

      • 7.4.1 Performing simple captures

      • 7.4.2 Matching using global expressions

      • 7.4.3 Referencing captures

      • 7.4.4 Non-capturing groups

    • 7.5 Replacing using functions

    • 7.6 Solving common problems with regular expressions

      • 7.6.1 Trimming a string

      • 7.6.2 Matching newlines

      • 7.6.3 Unicode

      • 7.6.4 Escaped characters

    • 7.7 Summary

  • Chapter 8: Taming threads and timers

    • 8.1 How timers and threading work

      • 8.1.1 Setting and clearing timers

      • 8.1.2 Timer execution within the execution thread

      • 8.1.3 Differences between timeouts and intervals

    • 8.2 Minimum timer delay and reliability

    • 8.3 Dealing with computationally-expensive processing

    • 8.4 Central timer control

    • 8.5 Asynchronous testing

    • 8.6 Summary

  • Chapter 9: Ninja alchemy: Run-time code evaluation

    • 9.1 Code evaluation mechanisms

      • 9.1.1 Evaluation with the eval() method

      • 9.1.2 Evaluation via the Function constructor

      • 9.1.4 Evaluation in the global scope

      • 9.1.5 Safe code evaluation

    • 9.2 Function decompilation

    • 9.3 Code evaluation in action

      • 9.3.1 Converting JSON

      • 9.3.2 Importing name-spaced code

      • 9.3.3 JavaScript compression and obfuscation

      • 9.3.4 Dynamic code rewriting

      • 9.3.5 Aspect-Oriented script tags

      • 9.3.6 Meta-languages

    • 9.4 Summary

  • Chapter 10: With statements

    • 10.1 What’s with with?

      • 10.1.1 Referencing properties within a with scope

      • 10.1.2 Assignments within a with scope

      • 10.1.3 Performance considerations

    • 10.2 Real-world examples

    • 10.3 Importing name-spaced code

    • 10.4 Testing

    • 10.5 Templating with with

    • 10.6 Summary

  • Chapter 11: Developing cross-browser strategies

    • 11.1 Choosing which browsers to support

    • 11.2 The five major development concerns

      • 11.2.1 Browser bugs and differences

      • 11.2.2 Bug fixes

      • 11.2.3 Living with external code and markup

      • 11.2.4 Missing Features

      • 11.2.5 Regressions

    • 11.3 Implementation strategies

      • 11.3.1 Safe cross-browser fixes

      • 11.3.2 Object detection

      • 11.3.3 Feature simulation

      • 11.3.4 Untestable browser issues

    • 11.4 Reducing assumptions

    • 11.5 Summary

  • Chapter 12: Cutting through attributes, properties and CSS

    • 12.1 DOM attributes and properties

      • 12.1.1 Cross-browser naming

      • 12.1.2 Naming restrictions

      • 12.1.3 XML differences from HTML

      • 12.1.4 Behavior of custom attributes

      • 12.1.5 Performance considerations

    • 12.2 Cross-browser attribute issues

      • 12.2.1 DOM id/name expansion

      • 12.2.2 URL normalization

      • 12.2.3 The style attribute

      • 12.2.4 The type attribute

      • 12.2.5 The tab index problem

      • 12.2.6 Node names

    • 12.3 Styling attribute headaches

      • 12.3.1 Where’re my styles?

      • 12.3.2 Style property naming

      • 12.3.3 The float style property

      • 12.3.4 Conversion of pixel values

      • 12.3.5 Measuring heights and widths

      • 12.3.6 Seeing through opacity

      • 12.3.7 Riding the color wheel

    • 12.4 Fetching computed styles

    • 12.5 Summary

  • Chapter 13: Surviving events

    • 13.1 Binding and unbinding event handlers

    • 13.2 The event object

    • 13.3 Handler management

      • 13.3.1 Centrally storing associated information

      • 13.3.2 Managing event handlers

    • 13.4 Triggering events

      • 13.4.1 Custom events

    • 13.5 Bubbling and delegation

      • 13.5.1 Delegating events to an ancestor

      • 13.5.2 Working around browser deficiencies

    • 13.6 The document ready event

    • 13.7 Summary

  • Chapter 14: Manipulating the DOM

    • 14.1 Injecting HTML into the DOM

      • 14.1.1 Converting HTML to DOM

      • 14.1.2 Inserting into the document

      • 14.1.3 Script execution

    • 14.2 Cloning elements

    • 14.3 Removing elements

    • 14.4 Text contents

      • 14.4.1 Setting text

      • 14.4.2 Getting text

    • 14.5 Summary

  • Chapter 15: CSS selector engines

    • 15.1 The W3C Selectors API

    • 15.2 Using XPath to find elements

    • 15.3 The pure DOM implementation

      • 15.3.1 Parsing the selector

      • 15.3.2 Finding the elements

      • 15.3.3 Filtering the set

      • 15.3.4 Recursing and merging

      • 15.3.5 Bottom Up Selector Engine

    • 15.4 Summary

Nội dung

[...]... some developers’ poor initial reaction to JavaScript may be that most developers are introduced to JavaScript in the browser So rather than reacting to JavaScript, The Language, they may be recoiling from the JavaScript bindings to the DOM API And the DOM API… well, let’s just say that it isn’t going to win any Friendliest API of the Year awards But that’s not JavaScript s fault Before we learn about... queue (a FIFO list, more on that later) as they occur, and the browser dispatches these events by invoking any handlers that have been established for them Because these events happen at unpredictable times and in an unpredictable order, we say that the handling of the events, and therefore the invocation of their handling functions, is asynchronous The types of events that can occur include:  Browser... first-class objects  How the browser invokes function  Declaring functions  The secrets of how functions are invoked  The context within a function You might have been somewhat surprised, upon turning to this first page of the part of this book dedicated to JavaScript fundamentals, to see that the topic of discussion is to be functions rather than objects We’ll certainly be paying plenty of attention to... pull it off, we need not only a mastery of the JavaScript language, but a thorough knowledge of the browsers, along with their quirks and inconsistencies, and a good grounding in accepted best practices While JavaScript development can certainly be challenging, there are those brave souls who have already gone down this torturous route: the developers of JavaScript libraries We’ll be distilling the knowledge... written to the console and be browsed immediately or at a later time without impeding the normal flow of the program – something not possible with alert() For example, if we wanted to know what the value of a variable named x was at a certain point in the code, we might write: console.log(x); If we were to assume that the value of x is 213, then the result of executing this statement in the Chrome... (If the notation used to create the function looks odd to you, be assured that we’ll be making it crystal clear in section 3.2.) Unobtrusive JavaScript This approach of assigning a function, named or otherwise, to the onload property of the window instance may not be the way that you are used to setting up a load handler You may be more accustomed to using the onload attribute of the tag Either... we also have the problem of determining if our code works in all the browsers that we choose to support We'll further discuss the problem of cross-browser development in-depth when we look at cross-browser strategies in chapter 11, but for now, it's vital that the importance of testing be emphasized and testing strategies defined, as we'll be using these strategies throughout the rest of the book In... objects (particularly in chapter 6), but when it comes down to brass tacks, the main difference between writing JavaScript code like the average Joe (or Jill) and writing it like a JavaScript Ninja, is understand JavaScript as a functional language The level of the sophistication of all the code that you will ever write in JavaScript hinges upon this realization If you’re reading this book, you’re... markup, CSS, or JavaScript as we can without disrupting the intent of the test case The more that we remove, the greater the likelihood that the test case will only be influenced by the specific code that we are trying to test • Independence – our tests should execute in isolation We must strive to not make the results from one test be dependent upon another We should break tests down into their smallest... JSUnit JSUnit is a port of the popular Java JUnit testing framework to JavaScript While it's still one of the most popular JavaScript unit testing frameworks around, JSUnit is also one of the oldest (both in terms of the code base age and quality) The framework hasn't been updated much recently, so for something that's known to work with all modern browsers, JSUnit may not be the best choice More information . the choices of those in the decision- making process, taking into account factors such as the skill of the developers, the needs of the market, and other. multiple considerations, the primary of which are:  The market share of the browser  The amount of effort necessary to support the browser Figure 1.2

Ngày đăng: 22/03/2014, 16:20

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN

w