
INDEX A architectural divisions, 449–450 Call Stack Technique, 460 addID mixin, 374–380 Family-Secret Technique, 450–452 addObserver function, 391–395 Imprinting Technique, 452–454 afterEach function, 39–40 Magic Wand Technique, 459–460 anonymous functions as callbacks, 121–123 Mission Impossible Technique, 454–459 AOP (aspect-oriented programming) testing, 473 advices, 58 args parameter, 291 argument checking, 301–303 arguments, 12 aspects, 58 checking, 290–301 caching, 58–59 AOP, 301–303 case studies versus object literals, 84 caching, 58–60 arrays, 291 module building, 60–72 asJSON( ) method, 354 contract enforcement, returned objects, AspectJS, 72–73 283–288 assert method, 282–283 cross-cutting concerns, 58 asynchronous callbacks, 111 libraries attachReturnValidator method, 285–287 AopJS jQuery plugin, 73 AspectJS, 72–73 YUI Do class, 73 B Memoization pattern and BDD (behavior-driven development), Jasmine, 39 aspect application, 159–160 beforeEach function, 39–40 aspect creation, 155–158 bind function, 311, 329–334 namespaces, 71–72 binding, this partial function applications, 147–148 COPYRIGHTEDdefault MATERIAL, 312–314 reliability, 60 explicit, 317 versus static solutions, 307–308 implicit, 314–316 testing and, 468–469 new and, 316–317 Aop object, 65–66 boolean data type, 82 AopJS jQuery plugin, 73 Boolean operations, 486–487 apply function, 311 borrow( ) method, 342 testing, 318–320, 472 borrowing methods. See method borrowing 489 bindex.indd 489 13/06/2015 6:04 PM caching – D.O.H. testing framework C coding standards, 444–449 installation, 436–439 caching, AOP and, 58–60 running, 439–444 call function, 311 testing, 472 testing, 318–320, 472 constructor functions, 90 Callback Pattern, 111–112 properties, 93 callback arrow, 121–123 correctness of code, 22–27 testing functions, 117–121 createATestObject method, 164 unit tests currying, 149–150 testing code, 112–117 writing code, 112–117 D writing functions, 117–121 callbackFcn, 321–322 D3 (Data-Driven Documents) callbacks, 111–112 case study, 5–15 arrows, 121–123 SVG line code generation, 7–8 asynchronous, 111 data types synchronous, 111 boolean, 82 testing, 117–121, 469 null, 82 testing code, 112–117 number, 82 this variable, 123–128 string, 82 writing, 117–121 undefined, 82 writing code, 112–117 Decorator Pattern, 205–206 chainable methods, 257–258 do-nothing decorators, 209–210 testing, 471–472 error pass through, 208–209 then, 258 fakes, 207–208 this, 259 features, 215–221 unit testing, 259–265 generalization, 222 chaining, Promise, 141–142 pass-through functionality, 210–213 chess analogy for patterns, 107–108 pass-through successes, 213–215 classical inheritance, 95–98 testing, 471 closures, 13 Dependency Inversion Principle (SOLID), 21 code describe function, 39–40 correctness, 22–27 design, 35-37 incorrect, 33–35 development minimum required, 36 small-scale versus large-scale, 5 optimization, 425–433 TDD (test-driven development), 23–24 reuse, 353 DI (dependency injection), 21, 45–46 code-checking tools, 73–74 case study, 47–55 JSHint, 76–79 frameworks alternatives, 79–80 AngularJS, 57–58 linting tools, 74–76 RequireJS, 56–57 Strict Mode, 80 using, 55–56 coding by contract, 17–18 reliability of code, 46–47 conformance, 435 system testing, 46 ESLint D.O.H. testing framework, 38–39 490 bindex.indd 490 13/06/2015 6:04 PM b DOM – functions DOM for loops, 109 access, testing, 473 extend function, 361–362 UI tests forEach loops, 109, 126 brittle, 424–425 frameworks code, 418–422 DI (dependency injection), 45–46 event handlers, 422–424 AngularJS, 57–58 done( ) function, 135 code reliability, 46–47 DRY principle, 4, 21–22 RequireJS, 56–57 classical inheritance emulation, 97–98 system testing, 46 functional inheritance, 98–99 using, 55–56 modules, 86 testing monkey patching, 102 D.O.H., 38–39 new object creation, 94 QUnit, 37–38 object literals and, 84 fulfills method, 278–282, 293 primitives and, 82–83 multipleFulfills method, 291 duck typing, 13 functional inheritance, 98–99 functions, 291. See also partial function E applications addObserver, 391–395 ECMAScript, polyfi lls and, 320–329 afterEach, 39–40 emulation, classical inheritance, 95–96 anonymous, 482–483 ESLint, 79–80 callbacks, 121–123 coding standards enforcement, 444–445 arguments, 484–485 custom rule, 445–448 versus object literals, 84 custom rules, 445–449 beforeEach, 39–40 installation bind, 329–334 Node and, 436–439 callbacks (See callbacks) npm and, 439 anonymous functions, 121–123 running, 439–442 testing, 117–121 all JavaScript fi les, 443–444 writing, 117–121 single fi le, 442–443 constructor functions, 90 evaluator function as interface, 276 properties, 93 event handlers, 329–334 declarations, 481–482 expect function, 41 describe, 39–40 extend function, 356–366 done( ), 135 expect, 41 extend, 356–366 F getID( ), 356 factories, 173 getProfile, 253–254 types, 180–181 incrementValue, 312–314 Factory Pattern interpolate, 10 implementing, 179–180 invoking, 485–486 testing, 470 arguments, 484–485 unit testing, 173–179 iterate, 113–115 fates, Promise, 143 line, 8–9 491 M bindex.indd 491 13/06/2015 6:04 PM getID – LRU line.x, 11–12 Interface Segregation Principle, 273–275 line.y, 11–12 as static data, 276 methods, attaching, 9 interpolate function, 10 nested, 9, 483–484 it function, Jasmine and, 39–40 scope and, 16–17 iterate function, 113–115, 319 as objects, 9, 481 prefetch, 245–246 properties, constructor functions, 93 J register, 51 Jasmine testing framework, 31 return types, 482 afterEach function, 39–40 returning functions, 9 BDD (behavior-driven development), 39 scope, 478–481 beforeEach function, 39–40 segment, 10 describe function, 39–40 setID( ), 356 expect function, 41 toThrow( ), 50 it function, 39–40 validateWithContractNameString, 296 matchers, 41 valIncrementor, 315–316 running tests, 32 specifi cations, 39–40 G spies, 41–44 suites, 39–40 getID( ) function, 356 test doubles, 41–44 getProfile function, 253–254 UI tests, 414–416 JavaScript, features, 4–5 jQuery, plugins, AopJS, 73 H JSHint, 76–80 HTTP GET, 206 JSLint, 79 HTTP POST, 206 HTTP requests, Promise and, 135–138 L I libraries, contracts, 303 line function, 8–9 incrementValue function, 312–314 x-accessor and, 12 inheritance line.x function, 11–12 classical line.y function, 11–12 emulating, 95–96 linting tools, 74–76 repetition, 96–98 Liskov, Barbara, 19–20 functional, 98–99 Liskov Subsitution Principle (SOLID), 19–20 object prototype, 88 literals instance of operator, 90–91 object literals, 83–84 instances, 161 Singleton Pattern and, 162–166 Interface Segregation Principle (SOLID), 20 loops interfaces for, 109 benefi ts, 272–273 forEach, 109, 126 evaluator function as, 276 LRU (least recently used) cache, 166 492 bindex.indd 492 13/06/2015 6:04 PM b Mediator Pattern – objects M functional, 373–380 TDD, 367–373 Mediator Pattern, 395–396 testing, 472 colleagues, 396 traditional mixins, 354 developing, 398–399 creating, 356–373 interfaces, 404–406 module pattern testing, 399–401 DRY and, 86 contracts, 403–404 module creation fakeMediator, 401 immediate execution, 85–86 game, 396–397 reliable, 86–87 interface segregation, 402–403 at will, 84–85 mediators, 396 SOLID and, 86 developing, 406–408 modules testing, 408–410 AOP, 60–72 testing, 473 versus scripts, 16 Memoization Pattern, 152 Singleton Pattern and, 166–170 AOP and, 155–160 monkey-patching, 100–102. See also method testing, 470 borrowing unit tests, 152–155 multipleFulfills method, 291 method borrowing, 102, 335–336 borrow( ) method, 342 functions qualifying borrower, 336–338 N objects namespaces, 71–72 aspect, 338–342 nested functions, 9 suitability, 336–343 scope and, 16–17 validator, 342–343 new keyword, 92 side effects, 343–350 this binding and, 316–317 donor objects, 350–351 new object creation pattern, 89–94 testing, 472 null data type, 82 methods. See also chainable methods; functions number data type, 82 asJSON( ), 354 assert, 282–283 attaching to functions, 9 O attachReturnValidator, 285–287 borrow( ), 342 objects createATestObject, 164 construction, testing, 469 fulfills, 278–282 creating, 30–31 iterate, 319 as dictionary, 476–477 multipleFulfills, 291 as functions, 9 then, 131–133, 258, 266–267 literals, 83–84 mixins, 353 versus arguments, 84 addID, 374–380 method borrowing and, 336–343, 350–351 creating, 355–356 new object creation pattern, 89–94 functional, 373–380 primitives, 81–82 traditional, 356–373 properties, adding/removing, 476 493 M bindex.indd 493 13/06/2015 6:04 PM Observer Pattern – Promise Pattern prototype Singleton, 161–162 chains, 88–89 Strategy Pattern, 223–237 default, 87–88 TDD and inheritance, 88 AOP, 468–469 wrappers, 82 apply function, 472 Observer Pattern, 384 architectural divisions, 473 addObserver function, 391–395 call function, 472 components, 384 callbacks, 469 recentRegistrationsService module, chainable methods, 471–472 385–391 conformance, 472 testing, 473 Decorator, 471 opeators, instance of, 90–91 DOM access, 473 Open/Closed Principle (SOLID), 19 Factory, 470 optimization, profi lers and Mediator, 473 ineffi ciency detection, 425–433 Memoization, 470 premature, 433 method borrowing, 472 mixins, 472 object construction, 469 P Observer, 473 parameters partial function applications, 470 args, 291 promise-based code, 469–470 type free, 290 Proxy, 471 partial function applications, 145 Sandbox, 470–471 AOP (aspect-oriented programming), 147–148 Singleton, 470 versus currying, 149–150 Strategy, 471 testing, 470 vocabulary and, 108–109 unit testing, 145–147 plugins, AopJS, 73 patterns polyfi lls, 320–329 Callback, 111–123 prefetch function,
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages10 Page
-
File Size-