作者:empty 页数:236 出版社:empty |
Evalua op irta rss ertetapphcaihionsaaoi5lg and Design PatternsJavaScriptPatterns rO'REILLY°YAHOO!PRESSStoyan Stefano uEval vs spes api cgi to.ocument was crea led whS pre.PDF for.NET.JavaScript Patterns“Slo yan basu rittenWhats the best approach for developing an application witht be go-to guide forJava Seri pt?This hook helps you answer that question withnumerous JavaScript coding patterns and bestpractices.Hf youreobjects, functions, inheritance, and other language-specificcategories, the abstractions and code templates in this guide areideal—whether you rewriting a client-side, server-side, or desktopapplication with JavaScript.Written by JavaScript expert Stoyan Stefanov—Senior Yahoo!Technical and architect of Y Slow 2.0, the webpage performanceoptimization tool-Jara Script Patterns in eludes practical advice forimplementing each pattern discussed, along with several hands-onexamples.Youllalsolearnaboutantipattems:commonprogram-ming approaches that cause more problems than they solve.■Explore useful habits for writing high-quality JavaScript■Discover different ways to define a function in JavaScript■Create objects that go beyond the basic patterns of usingmLe am the options av all able for code reuse and inheritancem Study sample JavaScript approaches to common design—Ryan GroveYUl engineer, Yahoo!code, such as avoiding globals, using single vardeclarations, and moremLe am why literal notation patterns are simpleralt em natives to constructor functionsobject literals and constructor functionsin JavaScriptpatterns such as Singleton, Factory, Decorator and morem Examine patterns that apply specifically to the client-sidebrowser environmentPre vous programming expe ince is recommended.USS 29.99CANS 34.99ISBN:978-0-596-80675-0978059680675052999Safari'f seo ie edt infor 45daya with purchase of
JavaScript Patterns
Evalua ion Warning:The document was created with Spire.PDF for.NET.JavaScript PatternsStoyan StefanovO'REILLY'Beijing·Cam bid ge·Fam ham·Koln·Sebastopol·TokyoJava Sc ptP attemsby Stoyan StefanovCopy rgh tO 2010 Yahoo, Inc..All ghts reservedPanted in the UniedSaesefAmenaPub ished by OReilly Media, In e, 1005 Gravenstein Highway North, Sebastopol, CA 95472O'Relly books maybe purchased for educational, business, or sales promotional use.On linc editionsareas eavlbletormosttlesht./nysufanbouksulinecem, Farm are m to mm at on, contact ourcomporate/institutanalsalesdepartment:(800)998-993Borcorporatctoreily.com.Editor:Mary Tres el erIndexer:Pot a mac Indexing.lLcProduction Editor:Teresa ElseyCover Designer:Karen Moni gomeryCopyeditor:Content Works, In eInteorDesinerDavdFua toProofreader:Teresa ElseyIllustrator:Robert RomanoPrnt ing History:September 2010.First Edi ionNur shel Handbook, theN us hell Handbook logo, and the OR elly logo are regi tered mr a de marks ofO'Relly Media, Inc.fovaSeriptParterns, the image of a European partridge.and related trade dress areira dem atk so fOR alMes, In eMany of the designations used by manufacturers and sellers to distinguish their pra ducts are claimed astrade marles.Where tha sedes ag nations appear in this book, and OReilly Media, Inc., was aware of atrademark dl aim, the designations have been pnn ted in caps or in i rial caps.While every precaution has been taken n the prep a tation of this book, the publi her and author assumenone sponsibility for errors or omissions, or for damages resulting from the use of the information con-tained herein:ISBN:97H-0-596-80675-0
With a subscription, you can read any page and watch any video from our library onlineRead books on your cellphone and mobile devices.Access new titles before they areavailable for print, and get exclusive access to manuscripts in development and postfeedback for the authors.Copy and paste code samples, organize your favorites, down-load chapters, bookmark key sections, create notes, print our pages, and benefit fromtons of other time-saving featureso'Reily Media has uploaded this book to the Safari Books Online service.To have fulldigital access to this book and others on similar topics from O'Reilly and other pub-lishers,signupforfreeathtp://my.safariboolsonline.com.Howto Contact UsPlease address comments and questions concerning this book to the publisher1005 Gravenstein Highway NorthWe have a webpage for this book, where we list errata.examples, and any additionalinformation.You can access this page atTo comment or ask technical que sions about this hook, send email to:For more information abour our books, conferences, Resource Centers, and theO'Reilly Network, see our website at:lam forever indebted to the incredible reviewers who shared their energy and knowl-edge to make a much better book for the good of the community.Their blogs andTwitter streams area constant source of a we, sharp observations, great ideas, and·Dmitry Sosh niko v(http://dmitrysoshnikow.com, @Dmitry Sosh niko v)·Andrea Giam march i(hrtp://webreflection.blogspo.com, @Web Reflection)Some of the pat tems in the book were ident fied by the author, based on experienceand on studies of popular JavaScript libraries such as jQuery and YUI.But most of thepatterns are identified and des en bed by the JavaScript community; therefore, this bookis a result of the collective work of many developers.To not interrupt the narrative withhistory and credits, alst of references and suggested additional reading is given on thebook'scompanionsiteathttp://www-jspatterns.com/book/reading.If lve missed a good and orginal aricle in the list of references, please accept myapologiesandcontactmesolcanaddittotheonlinelistathttp://jspatterns.com.This is not a beginner's book and some basic topics such as loops and conditions areskipped.
Introduction
Java Scrip r is the language of the Web.It started as away to manipulate a few selectedtypes of elements in a webpage(such as images and form fields) , but it has growntremendously.In addition to chen t-side browser scripting.these days you can useJava Scrip i to program for an increasing variety of platforms.You can write server-sidecode{using.NET or Node.js) , desktop applications(that work on all operating sys-tems) and application extensions(eg., for Firefox or Photoshop) , mobile applications,and command-line scriptsJavaScript is also an unusual language.It doesn't have classes, and functions are firs i-clss obj eets used for many tasks.In i ally the language was considered deficient bymany developers, but in more recent years these sentiments have changed.Interestingly, languages such as Java and PHP started adding features such as closures andanonymous functions, which JavaScript developers have been enjoying and taking forgranted for awhile.JavaScript is dynamic enough that you can make it look and feel like another languageyou real tea dy comfortable with.But the h etter approach is to embrace its differencesand study its specific patternsPatternsA pattern in the broader sense of the word is a“theme of recurring events or objects...it can be a template or model which can be used to generate things (htip:/len.wikipediaorg/wiki/Pattern) ,In software development.a pattern is a solution to a common problem.A pattern isnot necessarily a code solution ready for copy-and-paste but more of a best practice, auseful abstraction, and a template for solving categories of problems.It is important to identi ly patterns because:·They help us write better code using proven practices and not reinvent the wheel.·They provide a level of abstraction the brain can hold only so much at a giventime, so when you think about a more complex problem, it helps if you don'tb otherwith the low-level derails but account for them with self-contained building blocks(pat re rns) .·They improve communication between developers and teams, which are often inremote locations and don't communicate face to face.Simply putting a label onsome coding technique or approach makes it easier to make sure we're talkingabout the same thing.For example, it's easier to say(and think) “immediate func-tion, than“this thing where you wrap the function in parentheses and at the endof it put another set of parentheses to invoke the function right where you'vede-fined it”This book discusses the following types of patterns:·Design patterns·Coding patterns·Anti patternsDesign patterns are those initial y der in ed by the“Gang of Four book(named so afterits four authors) , originally published in distant 1994 under the title Design Patterns:Elements of Reusable Object-Oriented Softwar c.Examples of design patterns arcsin·g let on, factory, decorator, observer, and soon.The thing about design patterns inrelation to JavaScript is that, although language-independent, the design patterns weremostly studied from the perspective of strongly typed languages, such asC++and Java.Sometimes it doesn't neces san ly make sense to apply them verbatim in alons ely typeddynamic language such as JavaScript.Sometimes these patterns are workarounds thatdeal with the strongly typed nature of the languages and the class-based inheritance.In Java Scrip r there might be simpler alternatives.This book discusses JavaScript im-plementation s of several design patterns in Chapter 7.The coding patterns are much more interesting; they are JavaScript-speci ic patternsand good practices related to the unique features of the language, such as the varioususes of functions.JavaScript coding patterns are the main topic of the book.You might come across an occasional anti pattern in the hook.An tip attems have abitof negative or even insulting sound to their name, but that need n't be the case.Ananti pattern is not the sam casa bug or a coding error, it's just a common approach thatcauses more problems than it solves.Anti patterns are clearly marked with a commentin the code.
empty