Pro.JavaScript.Design.Patterns.pdf

所需积分/C币:18 2012-08-04 15:54:25 2.42MB PDF
收藏 收藏 1
举报

Pro.JavaScript.Design.Patterns.pdf
908Xch00FM qxd 11/16/07 1: 05 PM Page i Pro JavaScript Design Patterns Ross harmes and dustin diaz press 908Xch00FM qxd 11/16/07 1: 05 PM Page ii 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-10pbk):1-59059-908-X 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 visithttp://www.springeronline.com For information on translations, please contact Apress directly at 2855 Telegraph avenue, Suite 600 Berkeley Ca94705.Phone510-549-5930,fax510-549-5939,e-mailinfo@apress.com,orvisithttp://www.apress.com. 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 908xch00FM qxd 11/16/07 1: 05 PM Page iii To Mom, and those who have listened, thanks Dustin diaz To Alec, Dymphi, and Terry Ross harmes 908Xch00FM qxd 11/16/07 1: 05 PM Page iv 908Xch00FM qxd 11/16/07 1: 05 PM Page v 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 908Xch00FM qxd 11/16/07 1: 05 PM Page vi 908Xch00FM qxd 11/16/07 1: 05 PM Page vil Contents About the authors About the technical reviewer Acknowledgments XIX Introduction PART 1 Object-Oriented JavaScript CHAPTER 1 Expressive JavaScript he Flexibility of JavaScript A Loosely Typed Language Functions As First-Class objects 3-66 The mutability of objects Inheritance Design Patterns in JavaScript 8-9-9 Summary chaPTer 2 Interfaces What is an Interface? Benefits of Using Interfaces Drawbacks of Using Interfaces 1—122 How Other Object-Oriented Languages Handle Interfaces 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 908Xch00FM qxd 11/16/07 1: 05 PM Page vil CONTENTS CHAPTER 3 Encapsulation and Information Hiding The Information Hiding principle Encapsulation Vs Information Hiding The role of the interface Basic Patterns Fully Exposed object 5560670 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.pdf
立即下载 低至0.43元/次 身份认证VIP会员低至7折
    一个资源只可评论一次,评论内容不能少于5个字
    zhouchengyunew 大致翻了下觉着不错,还在看基础的部分,以后再深入研究
    2017-01-03
    回复
    关注 私信 TA的资源
    上传资源赚积分,得勋章
    最新推荐
    Pro.JavaScript.Design.Patterns.pdf 18积分/C币 立即下载
    1/127
    Pro.JavaScript.Design.Patterns.pdf第1页
    Pro.JavaScript.Design.Patterns.pdf第2页
    Pro.JavaScript.Design.Patterns.pdf第3页
    Pro.JavaScript.Design.Patterns.pdf第4页
    Pro.JavaScript.Design.Patterns.pdf第5页
    Pro.JavaScript.Design.Patterns.pdf第6页
    Pro.JavaScript.Design.Patterns.pdf第7页
    Pro.JavaScript.Design.Patterns.pdf第8页
    Pro.JavaScript.Design.Patterns.pdf第9页
    Pro.JavaScript.Design.Patterns.pdf第10页
    Pro.JavaScript.Design.Patterns.pdf第11页
    Pro.JavaScript.Design.Patterns.pdf第12页
    Pro.JavaScript.Design.Patterns.pdf第13页
    Pro.JavaScript.Design.Patterns.pdf第14页
    Pro.JavaScript.Design.Patterns.pdf第15页
    Pro.JavaScript.Design.Patterns.pdf第16页
    Pro.JavaScript.Design.Patterns.pdf第17页
    Pro.JavaScript.Design.Patterns.pdf第18页
    Pro.JavaScript.Design.Patterns.pdf第19页
    Pro.JavaScript.Design.Patterns.pdf第20页

    试读已结束,剩余107页未读...

    18积分/C币 立即下载 >