Pro JavaScript Design Patterns

所需积分/C币:10 2017-12-10 19:42:30 2.03MB PDF
收藏 收藏

As a web developer, you’ll already know that JavaScript™ is a powerful language, allowing you to add an impressive array of dynamic functionality to otherwise static web sites. But there is more power waiting to be unlocked--JavaScript is capable of full object-oriented capabilities, and by applying
Pro JavaScript Design Patterns Ross harmes and dustin diaz Apress° Pro JavaScript" Design Patterns Copyright o 2008 by Ross Harmes and dustin diaz All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher ISBN-13(pbk):978-1-59059-908-2 ISBN-10(pbk):1-59059908X ISBN-13( electronic:978-1-4302-0495-4 ISBN-10(electronic): 1-4302-0495-8 Printed and bound in the united states of america 987654321 Trademarked names may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name we use the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. Java and all Java-based marks are trademarks or registered trademarks of Sun Microsystems Inc in the United States and other countries. Apress Inc is not affiliated with Sun Microsystems InC. and this book was written without endorsement from Sun Microsystems Inc. Lead editors Chris Mills, Tom Welsh Technical Reviewer: Simon willison Editorial Board: Steve Anglin, Ewan Buckingham, Tony Campbell, Gary Cornell, Jonathan Gennick Jason Gilmore, Kevin Goff, Jonathan Hassell, Matthew Moodie, Joseph Ottinger, Jeffrey Pepper, Ben renow-Clarke, Dominic shakeshaft, Matt Wade. Tom Welsh Project Manager: Richard Dal Porto Copy Editor: Jennifer Whipple Associate Production Director: Kari Brooks-Copony Production Editor: Kelly Winquist Compositor and Artist: Kinetic Publishing Services, LLC Proofreader: dan shaw Indexer: Julie grady Cover Designer: Kurt Krames Manufacturing Director: Tom Debolski Distributed to the book trade worldwide by Springer-Verlag New York, Inc, 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax 201-348-4505, e-mail orders-ny@springer-sbm com, or visit For information on translations, please contact Apress directly at 2855 Telegraph avenue, Suite 600 Berkeley Ca94705.Phone510-549-5930,fax510-549-5939,,orvisit The information in this book is distributed on anas is"basis, without warranty. Although every precaution has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in this work Thesourcecodeforthisbookisavailabletoreadersathttp://www.apress.ce To Mom, and those who have listened, thanks Dustin diaz To Alec, Dymphi, and Terry Ross harmes Contents at a glance About the authors About the technical reviewer Acknowledgments XIX Introduction PART 1 Object-Oriented JavaScript CHAPTER 1 Expressive JavaScript CHAPTER 2 Interfaces CHAPTER3 Encapsulation and Information hiding 面面 25 CHAPTER 4 Inheritance ......,.41 CHAPTER 5 The Singleton Pattern CHAPTER 6 Chaining PART 2 Design patterns CHAPTER 7 The Factory Pattern CHAPTER 8 The bridge Pattern CHAPTER 9 The Composite Pattern 125 CHAPTER 10 The facade pattern CHAPTER 11 The Adapter Pattern .....149 CHAPTER 12 The decorator pattern .159 CHAPTER 13 The Flyweight Pattern 179 CHAPTER 14 The Proxy Pattern CHAPTER 15 The observer pattern 215 CHAPTER 16 The command pattern 225 CHAPTER 17 The Chain of Responsibility Pattern .245 INDEX Contents About the authors About the technical reviewer Acknowledgments XIX Introduction PART 1 Object-Oriented JavaScript CHAPTER 1 Expressive JavaScript The Flexibility of JavaScript A Loosely Typed Language Functions As First-Class objects The mutability of objects 8 Inheritance Design Patterns in JavaScript Summary chaPTer 2 Interfaces What is an Interface? Benefits of Using Interfaces Drawbacks of Using Interfaces 12 How other Object-Oriented Languages Handle Interfaces....... 12 Emulating an interface in Javascript Describing Interfaces with Comments Emulating Interfaces with Attribute Checking Emulating Interfaces with Duck Typing The Interface Implementation for this book The Interface Class .19 When to Use the interface class How to Use the interface class 20 Example: Using the Interface Class Patterns That rely on the Interface Summar CONTENTS CHAPTER 3 Encapsulation and Information Hiding The Information Hiding principle Encapsulation Vs Information Hiding The role of the interface 55606 Basic Patterns Fully Exposed Object Private Methods Using a naming convention Scope, Nested Functions, and closures Private Members Through Closures More Advanced patterns Static Methods and attributes Constants Singletons and object Factories 38 Benefits of Using Encapsulation Drawbacks to Using Encapsulation 39 Summary CHAPTER 4 Inheritance Why do you need Inheritance Classical Inheritance 42 The prototype chai 42 The extend function 43 Prototypal Inheritance Asymmetrical Reading and Writing of Inherited Members The clone function Comparing Classical and Prototypal Inheritance 49 Inheritance and encapsulation 49 Mixin classes Example: Edit-in-Place 52 Using classical Inheritance Using prototypal Inheritance Using Mixin Clas When should inheritance Be Used? Summary CHAPTER 5 The Singleton Pattern The Basic structure of the singleton Namespacing

试读 127P Pro JavaScript Design Patterns
立即下载 低至0.43元/次 身份认证VIP会员低至7折
    关注 私信 TA的资源
    Pro JavaScript Design Patterns 10积分/C币 立即下载
    Pro JavaScript Design Patterns第1页
    Pro JavaScript Design Patterns第2页
    Pro JavaScript Design Patterns第3页
    Pro JavaScript Design Patterns第4页
    Pro JavaScript Design Patterns第5页
    Pro JavaScript Design Patterns第6页
    Pro JavaScript Design Patterns第7页
    Pro JavaScript Design Patterns第8页
    Pro JavaScript Design Patterns第9页
    Pro JavaScript Design Patterns第10页
    Pro JavaScript Design Patterns第11页
    Pro JavaScript Design Patterns第12页
    Pro JavaScript Design Patterns第13页
    Pro JavaScript Design Patterns第14页
    Pro JavaScript Design Patterns第15页
    Pro JavaScript Design Patterns第16页
    Pro JavaScript Design Patterns第17页
    Pro JavaScript Design Patterns第18页
    Pro JavaScript Design Patterns第19页
    Pro JavaScript Design Patterns第20页


    10积分/C币 立即下载 >