0 Usuarios y 1 Visitante están viendo este tema.
PART 1 PREPARING FOR TRAINING . ...............................11 Enter the ninja 31.1 The JavaScript libraries we’ll be tapping 41.2 Understanding the JavaScript language 51.3 Cross-browser considerations 61.4 Current best practices 9Current best practice: testing 9 ■ Current best practice:performance analysis 101.5 Summary 112 Arming with testing and debugging 132.1 Debugging code 14Logging 14 ■ Breakpoints 16vi CONTENTS2.2 Test generation 172.3 Testing frameworks 19QUnit 21 ■ YUI Test 22 ■ JsUnit 22Newer unit-testing frameworks 222.4 The fundamentals of a test suite 22The assertion 23 ■ Test groups 24 ■ Asynchronous testing 252.5 Summary 27PART 2 APPRENTICE TRAINING.....................................293 Functions are fundamental 313.1 What’s with the functional difference? 32Why is JavaScript’s functional nature important? 33Sorting with a comparator 373.2 Declarations 40Scoping and functions 433.3 Invocations 46From arguments to function parameters 47 ■ Invocation asa function 49 ■ Invocation as a method 50 ■ Invocation asa constructor 52 ■ Invocation with the apply() andcall() methods 543.4 Summary 584 Wielding functions 614.1 Anonymous functions 624.2 Recursion 64Recursion in named functions 64 ■ Recursion with methods 65The pilfered reference problem 66 ■ Inline named functions 68The callee property 704.3 Fun with function as objects 71Storing functions 72 ■ Self-memoizing functions 73Faking array methods 764.4 Variable-length argument lists 77Using apply() to supply variable arguments 77Function overloading 794.5 Checking for functions 864.6 Summary 88CONTENTS vii5 Closing in on closures 895.1 How closures work 905.2 Putting closures to work 94Private variables 94 ■ Callbacks and timers 965.3 Binding function contexts 995.4 Partially applying functions 1035.5 Overriding function behavior 106Memoization 106 ■ Function wrapping 1095.6 Immediate functions 111Temporary scope and private variables 112 ■ Loops 115Library wrapping 1175.7 Summary 1186 Object-orientation with prototypes 1196.1 Instantiation and prototypes 120Object instantiation 120 ■ Object typing via constructors 127Inheritance and the prototype chain 128HTML DOM prototypes 1336.2 The gotchas! 135Extending Object 135 ■ Extending Number 136Subclassing native objects 137 ■ Instantiation issues 1396.3 Writing class-like code 143Checking for function serializability 146 ■ Initializationof subclasses 147 ■ Preserving super-methods 1486.4 Summary 1507 Wrangling regular expressions 1517.1 Why regular expressions rock 1527.2 A regular expression refresher 153Regular expressions explained 153 ■ Terms and operators 1547.3 Compiling regular expressions 1587.4 Capturing matching segments 161Performing simple captures 161 ■ Matching usingglobal expressions 162 ■ Referencing captures 163Non-capturing groups 1657.5 Replacing using functions 166viii CONTENTS7.6 Solving common problems with regular expressions 168Trimming a string 168 ■ Matching newlines 170Unicode 171 ■ Escaped characters 1727.7 Summary 1728 Taming threads and timers 1758.1 How timers and threading work 176Setting and clearing timers 176 ■ Timer execution withinthe execution thread 177 ■ Differences between timeoutsand intervals 1798.2 Minimum timer delay and reliability 1808.3 Dealing with computationally expensive processing 1838.4 Central timer control 1868.5 Asynchronous testing 1898.6 Summary 190PART 3 NINJA TRAINING ............................................1919 Ninja alchemy: runtime code evaluation 1939.1 Code evaluation mechanisms 194Evaluation with the eval() method 194 ■ Evaluation via theFunction constructor 197 ■ Evaluation with timers 197Evaluation in the global scope 198 ■ Safe code evaluation 1999.2 Function “decompilation” 2019.3 Code evaluation in action 204Converting JSON 204 ■ Importing namespaced code 205JavaScript compression and obfuscation 206 ■ Dynamiccode rewriting 208 ■ Aspect-oriented script tags 209Metalanguages and DSLs 2109.4 Summary 21310 With statements 21510.1 What’s with “with”? 216Referencing properties within a with scope 216 ■ Assignmentswithin a with scope 218 ■ Performance considerations 21910.2 Real-world examples 22110.3 Importing namespaced code 223CONTENTS ix10.4 Testing 22310.5 Templating with “with” 22410.6 Summary 22711 Developing cross-browser strategies 22911.1 Choosing which browsers to support 23011.2 The five major development concerns 231Browser bugs and differences 232 ■ Browser bug fixes 233Living with external code and markup 234Missing features 239 ■ Regressions 24011.3 Implementation strategies 242Safe cross-browser fixes 242 ■ Object detection 243Feature simulation 245 ■ Untestable browser issues 24711.4 Reducing assumptions 24911.5 Summary 25112 Cutting through attributes, properties, and CSS 25312.1 DOM attributes and properties 255Cross-browser naming 256 ■ Naming restrictions 257Differences between XML and HTML 257 ■ Behavior ofcustom attributes 258 ■ Performance considerations 25812.2 Cross-browser attribute issues 262DOM id/name expansion 262 ■ URL normalization 264The style attribute 265 ■ The type attribute 265The tab index problem 266 ■ Node names 26712.3 Styling attribute headaches 267Where are my styles? 268 ■ Style property naming 270The float style property 271 ■ Conversion of pixel values 271Measuring heights and widths 272 ■ Seeing throughopacity 276 ■ Riding the color wheel 27912.4 Fetching computed styles 28212.5 Summary 285PART 4 MASTER TRAINING.........................................28713 Surviving events 28913.1 Binding and unbinding event handlers 29013.2 The Event object 294x CONTENTS13.3 Handler management 297Centrally storing associated information 298Managing event handlers 30013.4 Triggering events 309Custom events 31013.5 Bubbling and delegation 315Delegating events to an ancestor 315 ■ Working aroundbrowser deficiencies 31613.6 The document ready event 32413.7 Summary 32614 Manipulating the DOM 32914.1 Injecting HTML into the DOM 330Converting HTML to DOM 331 ■ Inserting intothe document 334 ■ Script execution 33614.2 Cloning elements 33814.3 Removing elements 34014.4 Text contents 341Setting text 342 ■ Getting text 34314.5 Summary 34415 CSS selector engines 34515.1 The W3C Selectors API 34715.2 Using XPath to find elements 34915.3 The pure-DOM implementation 351Parsing the selector 353 ■ Finding the elements 354Filtering the set 355 ■ Recursing and merging 356Bottom-up selector engine 35715.4 Summary 359
https://jumpshare.com/v/rJXhwuiOvGtquVj6sOGw