[{"data":1,"prerenderedAt":13728},["ShallowReactive",2],{"search-index-blog":3,"blog-\u002Fblog\u002Fjavascript-design-patterns":917,"surround-\u002Fblog\u002Fjavascript-design-patterns":13723},[4,11,19,24,30,35,41,46,52,57,62,67,72,78,84,90,95,101,107,113,118,125,130,135,141,146,151,156,163,168,174,179,185,190,195,200,205,210,215,221,226,231,236,241,246,251,256,261,266,272,277,282,287,293,298,304,309,314,319,325,330,335,340,345,351,356,363,368,373,378,384,389,394,399,405,410,415,420,426,432,437,443,448,454,459,464,469,474,480,485,490,495,500,505,510,515,521,526,531,537,542,547,552,557,562,567,573,579,584,589,594,599,604,609,614,620,625,630,635,640,645,651,656,661,666,671,676,682,687,692,697,702,707,712,719,724,729,734,739,745,750,755,760,765,770,775,780,786,791,797,802,808,813,818,823,829,834,839,844,849,854,860,865,871,876,881,886,891,896,901,906,912],{"title":5,"path":6,"description":7,"tags":8},"ADOBE ILLUSTRATOR SHORTCUTS","\u002Fblog\u002Fadobe-illustrator-shortcuts","Here are 26 Adobe Illustrator shortcuts that can help you to speed up productivity. I use most of them (in fact, I can’t work without them). Most of shortcuts listed in this article aren’t documented in the software, so keep reading and you’re sure to find at least one new trick to put up your sleeve. Enjoy!",[9,10],"design","illustrator",{"title":12,"path":13,"description":14,"tags":15},"ANGULAR CONTROLLERS SHARE STATE","\u002Fblog\u002Fangular-controllers-share-state","When your Angular.js application expands to a state that you no longer find it easy to understand, it's time you used dependency injection and modularise your application into units of interrelated modules.",[16,17,18],"development","javascript","angular.js",{"title":20,"path":21,"description":22,"tags":23},"ANGULAR TRANSLATE","\u002Fblog\u002Fangular-translate","Angular Translate is an AngularJS module called angular-translate which makes i18n and l10n easier with your Angular application. The acronym i18n stands for internationalization, and l10n for localization.",[16,17,18],{"title":25,"path":26,"description":27,"tags":28},"ANIMATION SPEED IN JAVASCRIPT AND CSS","\u002Fblog\u002Fanimation-speed-in-javascript-and-css","In this article, we go through how JavaScript-based DOM animation libraries, such as Velocity.js and GSAP, are more efficient than jQuery and CSS-based animation libraries. We will discuss how those libraries work, where to use them and what other alternatives are out there for animation.",[16,17,29],"css",{"title":31,"path":32,"description":33,"tags":34},"ARRAY COMPREHENSIONS","\u002Fblog\u002Farray-comprehensions","Array comprehension is creating a list B based on another list A, where each entry of B is the result of a custom operation performed on the items of list A.",[16,17],{"title":36,"path":37,"description":38,"tags":39},"ASYNCHRONOUS JAVASCRIPT WITH ASYNC\u002FAWAIT","\u002Fblog\u002Fasynchronous-javascript-asyncawait","'Promises are great but the its nested syntax can get easily complex and hard to follow.",[16,17,40],"react",{"title":42,"path":43,"description":44,"tags":45},"BABEL & WEBPACK","\u002Fblog\u002Fbabel-webpack","Babel has been one of the big newcomers of JavaScript community in 2015. It allows us to use features from the future of JavaScript. It will transform your futuristic code into a format, browsers understand. You can even use it to develop your own language features. Babel’s built-in JSX support will come in handy here.",[16,17],{"title":47,"path":48,"description":49,"tags":50},"BACKBONE CUSTOMIZING COLLECTIONS","\u002Fblog\u002Fbackbone-customizing-collections","Backbone collections are an ordered set of models, which only use one type of model. Customizing these collections can help your Backbone application to leverage data the way you want.",[16,17,51],"backbone.js",{"title":53,"path":54,"description":55,"tags":56},"BACKBONE – MODELS","\u002Fblog\u002Fbackbone-models","Models are the heart of any JavaScript MVC application, containing the interactive data as well as a large part of the logic surrounding it: conversions, validations, computed properties, and access control.",[16,17,51],{"title":58,"path":59,"description":60,"tags":61},"BACKBONE PATTERNS","\u002Fblog\u002Fbackbone-patterns","In this article, we’ll discuss different patterns that you can use with popular open-source JavaScript MV* framework, Backbone.js.  Developers run into problems when they first use Backbone.js as it provides structure to the application leaving the developer to make decisions on design petterns.",[16,17,51],{"title":63,"path":64,"description":65,"tags":66},"BACKBONE- ROUTERS","\u002Fblog\u002Fbackbone-routers","In the traditional MVC sense Routers don’t necessarily fit the semantics. Though a Backbone \"router\" is still very useful for any application\u002Ffeature that needs URL routing\u002Fhistory capabilities. Backbone routers are used for routing your applications URL’s when using hash tags(#).",[16,17,51],{"title":68,"path":69,"description":70,"tags":71},"BEM","\u002Fblog\u002Fbem","BEM stands for Block, Element, Modifier. BEM is a stricter standard for naming CSS classes for larger projects, where standards need to be enforced. BEM helps scale your project, and add meaning to your CSS. Therefore it is valuable to understand this convention.",[16,29],{"title":73,"path":74,"description":75,"tags":76},"BENEFITS OF AUTOMATED DEPLOYMENT","\u002Fblog\u002Fbenefits-of-automated-deployment","When deploying software manually, the tendancy is to deploy once a month or perhaps once every two or three months. Deployment doesn’t stop for production only, there are test, staging and production as well.",[16,77],"deployment",{"title":79,"path":80,"description":81,"tags":82},"BROWSERSYNC & GULP","\u002Fblog\u002Fbrowsersync-gulp","BrowserSync & Gulp are a two very useful combination when it comes to developing applications efficiently, without having to refresh the web page every time you make a change. Let’s look at what BrowserSync & Gulp are, and how to install and use them.",[16,17,83],"gulp",{"title":85,"path":86,"description":87,"tags":88},"CHROMATIC ABERRATION","\u002Fblog\u002Fchromatic-aberration","In optical lenses, chromatic aberration (also known as achromatism or chromatic distortion) is a type of  distortion in which there is a failure of a lens to focus all colors to the same convergence point.",[89],"photography",{"title":91,"path":92,"description":93,"tags":94},"CHROME DEVTOOLS FOR WEB APP DEVELOPERS","\u002Fblog\u002Fchrome-devtools-web-app-developers","The Chrome DevTools (Developer Tools), are a set web authoring and debugging tools built into Google Chrome. The DevTools provide web developers deep access into the internals of the browser and their web application. ",[16,17],{"title":96,"path":97,"description":98,"tags":99},"COFFEESCRIPT INTRODUCTION","\u002Fblog\u002Fcoffeescript-introduction","CoffeeScript is a language that makes JavaScript easier to write and read. It simplifies JavaScript, making it readable and understandable, as well easier to maintain. CoffeeScript compiles into JavaScript",[16,17,100],"coffeescript",{"title":102,"path":103,"description":104,"tags":105},"COFFEESCRIPT – JQUERY","\u002Fblog\u002Fcoffeescript-jquery","Writing jQuery in CoffeeScript, further simplifies the syntax. The jQuery(function($)) can be written as jQuery($) -> or simply $ ->.",[16,17,106,100],"jquery",{"title":108,"path":109,"description":110,"tags":111},"CONTENT AWARE SCALING IN PHOTOSHOP","\u002Fblog\u002Fcontent-aware-scaling-in-photoshop","In Photoshop CS6, content-aware scaling (also known as seam carving) is a cool image-sizing feature.",[9,112],"photoshop",{"title":114,"path":115,"description":116,"tags":117},"CREATE FAVICONS IN PHOTOSHOP","\u002Fblog\u002Fcreate-favicons-in-photoshop","'Having a favicon for your site helps users to find your web site on a bookmarks bar, or among open tabs.",[9,112],{"title":119,"path":120,"description":121,"tags":122},"CREATE A RAILS 5 API APPLICATION","\u002Fblog\u002Fcreate-rails-5-api-application","'Rails 5 ships a new gem rails-api which makes building API only rails apps a breeze.",[16,123,124],"rails","ruby",{"title":126,"path":127,"description":128,"tags":129},"CSS – CLEARING FLOATS","\u002Fblog\u002Fcss-clearing-floats","A common problem with float-based layouts is that the floats' container doesn't want to stretch up to accommodate the floats. If you want to add, say, a border around all floats (ie. a border around the container) you'll have to command the browsers somehow to stretch up the container all the way.",[16,17],{"title":131,"path":132,"description":133,"tags":134},"CSS INTRODUCTION","\u002Fblog\u002Fcss-introduction","Cascading Style Sheets (CSS) is a style sheet language used for describing the look and formatting of a document written in a markup language, most often used to change the style of web pages written in HTML. CSS is designed primarily to enable the separation of document content from document presentation, including elements such as the layout, colors, and fonts.",[16,29],{"title":136,"path":137,"description":138,"tags":139},"CSS MODULES","\u002Fblog\u002Fcss-modules","A CSS Module is a CSS file in which all class names and animation names are scoped locally by default, eleminating the problems with global nature of the CSS namespace.",[16,17,29,140],"react.js",{"title":142,"path":143,"description":144,"tags":145},"CSS3 MEDIA QUERIES","\u002Fblog\u002Fcss3-media-queries","When you are designing your responisve layout for mobile devices, CSS3 media queries are an essential component on your stylesheets. Let’s discuss how they work and what min-with and max-with work together.",[16,29],{"title":147,"path":148,"description":149,"tags":150},"DEFERRED AND PROMISE IN JQUERY","\u002Fblog\u002Fdeferred-and-promise-in-jquery","Deferred and promise are part of jQuery since version 1.5 and they help in handling asynchronous functions like Ajax.",[16,17,106],{"title":152,"path":153,"description":154,"tags":155},"DEPLOYING ASP.NET MVC APPLICATIONS","\u002Fblog\u002Fdeploying-aspnet-mvc-applications","In a continuous integration environment, deploying ASP.NET MVC applications are done by a click of a button, triggered by a check-in, and then  many moving parts of the integration service will take care of distributing the artifacts to the relevant  servers. But here we are discussing about how to get your ASP.NET code to be tested on a local IIS server environment. So let’s start with dependancies, and what needs to be included with the deployment.",[16,17],{"title":157,"path":158,"description":159,"tags":160},"DEVELOP MOBILE APPS WITH PHONEGAP","\u002Fblog\u002Fdevelop-mobile-apps-phonegap","PhoneGap is a web-based mobile development framework based on opened source Cordova project, which allows you to create app store ready mobile applications. PhoneGap allows you to use web technologies such as HTML, CSS and JavaScript for cross platform development. It was created by Nitobi in 2009. In 2011, Nitobi was bought by Adobe, and PhoneGap was donated to Apache Foundation, and PhoneGap was renamed to Cordova.",[16,161,17,162],"mobile","phonegap",{"title":164,"path":165,"description":166,"tags":167},"DODGE BURN AND SPONGE TOOLS IN PHOTOSHOP CS6","\u002Fblog\u002Fdodge-burn-and-sponge-tools-in-photoshop-cs6","The Dodge, Burn, and Sponge tools in Photoshop CS 6 can be used to correct the lighting of an image. Let’s look at each of these tools and what they are useful for.",[9,89,112],{"title":169,"path":170,"description":171,"tags":172},"EMBER & HANDLEBARS","\u002Fblog\u002Fember-handlebars","Before getting into handlebars, let's look at how routing works in Ember.js. Router is solely responsible for all URLs in Ember.",[16,17,173],"ember.js",{"title":175,"path":176,"description":177,"tags":178},"EMBER – RESOURCE ROUTES","\u002Fblog\u002Fember-resource-routes","The difference between resource() and route() in Ember.js is that you should use this.resource for URLs that represent a noun, and this.route for URLs that represent adjectives or verbs modifying those nouns.",[16,17,173],{"title":180,"path":181,"description":182,"tags":183},"ENTITY FRAMEWORK CODE FIRST","\u002Fblog\u002Fentity-framework-code-first","Entity Framework introduced Code First approach from Entity Framework 4.1. This tutorial covers all the features of Entity Framework Code-First. We will start with the basics of code-first and then we will see how we can configure one-to-one, one-to-many and many-to-many relationship with DataAnnotation as well as Fluent API.",[16,184],"csharp",{"title":186,"path":187,"description":188,"tags":189},"ES2020 New Features","\u002Fblog\u002Fes2020-new-features","Since ES2015, updates from the TC39 committee are released annually. Their latest release ES2020 comes with many new features.",[16,17],{"title":191,"path":192,"description":193,"tags":194},"ES6 ADVANCED FEATURES","\u002Fblog\u002Fes6-advanced-features","We have learned about the new features ES6 brings us in ES6 New Features article. In this post, we will go through the advanced features of ES6 and how we can implement them.",[16,17],{"title":196,"path":197,"description":198,"tags":199},"ES6 ARROW FUNCTIONS","\u002Fblog\u002Fes6-arrow-functions","Arrow functionss are a function shorthand using the => syntax (fat arrow). They are syntactically similar to the related feature in C#, Java 8 and CoffeeScript. They support both expression and statement bodies. Unlike functions, arrows share the same lexical this as their surrounding code.",[16,17],{"title":201,"path":202,"description":203,"tags":204},"ES6 CLASSES","\u002Fblog\u002Fes6-classes","JavaScript classes are simply syntactic sugar over existing JavaScript prototype chain. But classes give you a cleaner way to organise your code, and make it slightly easier for the beginner or people who are familiar with class oriented languages to read JS and understand.",[16,17],{"title":206,"path":207,"description":208,"tags":209},"ES6 DEFAULT, REST & SPREAD","\u002Fblog\u002Fes6-default-rest-spread","Many programming languages support the concept of a default argument for a function parameter so that the caller does not always need to specify the argument value. Unfortunately, ES5 does not have a default argument support in its syntax. ES6 functions have come a long way by taking aboard the years of complaints and improving parameter handling that is less error-prone and more powerful.",[16,17],{"title":211,"path":212,"description":213,"tags":214},"ES6 DESTRUCTURING","\u002Fblog\u002Fes6-destructuring","The destructuring assignment syntax is a JavaScript expression in ES6 that makes it possible to extract data from arrays or objects using a syntax that mirrors the construction of array and object literals.",[16,17],{"title":216,"path":217,"description":218,"tags":219},"ES6 GENERATORS","\u002Fblog\u002Fes6-generators","ES6 generators are functions that can be paused or resumed, and work cooperatively in a multitasking applications.",[16,17,220],"es6",{"title":222,"path":223,"description":224,"tags":225},"ES6 ITERATORS & FOR..OF","\u002Fblog\u002Fes6-iterators-for-of","To loop over an array or a collection JavaScript has been traditionally using for loops. ES5 introduced the for ..each loop. But ES6 introduces a little shorter version, a new interface for iteration called Iterable.",[16,17],{"title":227,"path":228,"description":229,"tags":230},"ES6 LET & CONST","\u002Fblog\u002Fes6-let-const","If you are familiar with JavaScript, you have probably known the term scope. If you are familiar with other languages, you would know that a scope of a variable is to the nearest block – block scope. But JavaScript is different. A variable created with var will be scoped to the nearest parent function.",[16,17],{"title":232,"path":233,"description":234,"tags":235},"ES6 MODULES","\u002Fblog\u002Fes6-modules","A module is a self-contained unit of code, which is usually stored in a file. In ES6, modules get language-level support for component definition. Modules export values, which can then be imported by other modules.",[16,17],{"title":237,"path":238,"description":239,"tags":240},"ES6 NEW FEATURES","\u002Fblog\u002Fes6-new-features","Arrows are a function shorthand using the => syntax (‘fat arrow’). They are syntactically similar to the related feature in C#, Java 8 and CoffeeScript. They support both expression and statement bodies. Unlike functions, arrows share the same lexical this as their surrounding code.",[16,17],{"title":242,"path":243,"description":244,"tags":245},"WEB APPLICATION SECURITY","\u002Fblog\u002Fes6-parameter-handling","ES6 introduced improved parameter handling in JavaScript. Instead of the half array arguments object, these new improvements will significantly improve how we handle arguments and parameters.",[16,17,220],{"title":247,"path":248,"description":249,"tags":250},"ES6 RECURSION WITH FUNCTIONAL PROGRAMMING","\u002Fblog\u002Fes6-recursion-with-functional-programming","In this article, we are going to use ES6 recursion with functional programming to understand how we can implement list operations like map, reduce, filter and join.",[16,17,220],{"title":252,"path":253,"description":254,"tags":255},"ES6 SYMBOLS","\u002Fblog\u002Fes6-symbols","Symbols are a new primitive type in ES6. If you ask me, they’re an awful lot like strings. They are tokens that serve as unique IDs. They will help avoid name clashes between properties.",[16,17],{"title":257,"path":258,"description":259,"tags":260},"ES6 TEMPLATE STRINGS","\u002Fblog\u002Fes6-template-strings","Template strings in JavaScript consist of literal text, and placeholders where the runtime can evaluate an expression to inject data into the text.",[16,17],{"title":262,"path":263,"description":264,"tags":265},"ESLINT","\u002Fblog\u002Feslint","ESLint is a pattern identifying and reporting tool for JavaScript code. Somewhat it is similar to JSLint and JSHint with few differences.",[16,17],{"title":267,"path":268,"description":269,"tags":270},"EXT JS DEVELOPING RESPONSIVE APPLICATIONS","\u002Fblog\u002Fext-js-developing-responsive-applications","Creating responsive web applications have been made easier with the arrival of the new JavaScript Framework Ext JS 5. In this article let's look at how we can use responsiveConfig to implement this feature.",[16,17,271],"ext.js",{"title":273,"path":274,"description":275,"tags":276},"EXT.JS – INTRODUCTION","\u002Fblog\u002Fext-js-introduction","Ext JS is a product of Sencha. Ext JS is the industry’s most powerful desktop application development platform with unparalleled cross-browser compatibility, advanced MVC architecture, plugin-free charting, and modern UI widgets.",[16,17,271],{"title":278,"path":279,"description":280,"tags":281},"FETCH API","\u002Fblog\u002Ffetch-api","The Fetch API is a Promise-based standard for performing AJAX requests. It provides a fetch method which returns a Promise on the window object, which we can use to perform requests from remote resources.",[16,17],{"title":283,"path":284,"description":285,"tags":286},"FOCAL LENGTH AND F-STOP","\u002Fblog\u002Ffocal-length-f-stop","Very simply, focal-length is the distance from the lens to the film, when focused on a subject at infinity. In other words, focal length equals image distance for a far subject. To focus on something closer than infinity, the lens is moved farther away from the film or sensor. This is why most lenses get longer when you turn the focusing ring.",[89],{"title":288,"path":289,"description":290,"tags":291},"FOUNDATION 5 NEW FEATURES","\u002Fblog\u002Ffoundation-5-new-features","ZURB’s Foundation framework is a feature-rich, easy to implement,  light weight framework for designing responsive web applications. Designed with mobile-first approach in mind,  it comes packed with CSS3 media queries, The Grid, reusable HTML5 components and several jQuery plugins to aid interactivity.",[16,29,292],"sass",{"title":294,"path":295,"description":296,"tags":297},"FREE PHOTOSHOP PLUGINS","\u002Fblog\u002Ffree-photoshop-plugins","There are so many amazing free Photoshop plugins you can download for Photoshop CS6 and CC. There are plugins for photo effects, noise reduction, painting, abstract art, layouts, and more! Let’s have a look at few of the best.",[9,112],{"title":299,"path":300,"description":301,"tags":302},"FRONT END PERFORMANCE","\u002Fblog\u002Ffront-end-performance","Front end performance can be a great experience or a horrifying nightmare that could highly impact the end user experience, and lead to users leaving your website.",[16,303],"performance",{"title":305,"path":306,"description":307,"tags":308},"FUNCTIONAL JAVASCRIPT","\u002Fblog\u002Ffunctional-javascript","To understand Functional JavaScript and the quirks of JavaScript, we will have to look into the history of JavaScript and how it was created.",[16,17],{"title":310,"path":311,"description":312,"tags":313},"FUNCTIONAL PROGRAMMING","\u002Fblog\u002Ffunctional-programming","Abstract control flow and operations on data with functions in order to avoid side effects & reduce mutation of state",[16,17],{"title":315,"path":316,"description":317,"tags":318},"GIT – CLONING & BRANCHING","\u002Fblog\u002Fgit-cloning-branching","Imagine you are working in a team and one of your colleagues wants a copy of the your work, how do we start collaborating?",[16,17],{"title":320,"path":321,"description":322,"tags":323},"GIT INTRODUCTION","\u002Fblog\u002Fgit-introduction","Git is a distributed source control system, that is lighting fast and different from client-server systems. In this tutorial, we will learn how to get started with Git. By the end of this tutorial, you should be able to create a Git repository, record snapshots of your project for safekeeping, and view your project's history.",[16,324],"git",{"title":326,"path":327,"description":328,"tags":329},"GIT STAGING & REMOTES","\u002Fblog\u002Fgit-staging-remotes","Let’s say you are working on your local branch, made some changes and now not sure which files you have changed, how are you going to find your changes? You can find your changes by running the git diff command as below:",[16,324],{"title":331,"path":332,"description":333,"tags":334},"GIT STASH","\u002Fblog\u002Fgit-stash","Say you are halfway done with work on a branch, but an issue with 'master' needs fixing NOW. You're not quite ready to commit what you're working on, but need to make a quick fix to master. Fear not, just stash your current changes so you can switch to master quickly.",[16,324],{"title":336,"path":337,"description":338,"tags":339},"GOOGLE DRIVE – AUTHENTICATION","\u002Fblog\u002Fgoogle-drive-authentication","When you are developing an application interfacing Google Driver API, it's mandatory to consider how you are going to handle the authentication for your user. In this article, we are discussing how to implement Google Drive Authentication for your app via its API.",[16,17],{"title":341,"path":342,"description":343,"tags":344},"GOOGLE PICKER WITH DRIVE","\u002Fblog\u002Fgoogle-picker-with-drive","\"Google Drive is a file storage service that enables users to organize, backup, and",[16,17],{"title":346,"path":347,"description":348,"tags":349},"GRUNT WATCH & LIVERELOAD WITH JAVASCRIPT & SASS","\u002Fblog\u002Fgrunt-watch-livereload-with-javascript-sass","Grunt is a task runner that has a ton of plugins for doing things like compiling LESS\u002FSASS into CSS, concatenating JavaScript, minifying, etc. It also has a package for watching files (the same way CodeKit and Prepros does) and firing off certain tasks when they’re modified.",[16,17,350],"grunt",{"title":352,"path":353,"description":354,"tags":355},"HOW TO USE GRUNT","\u002Fblog\u002Fhow-to-use-grunt","In this article, we’ll look at how to use Grunt in your project to automate some of your repetitive tasks. We’ll look at what Grunt is, how to setup Grunt and then create a simple project with Grunt doing the heavy lifting of the some of the tasks.",[16,17,350],{"title":357,"path":358,"description":359,"tags":360},"HOW TO ADD A COVER TO AN EPUB, PDF OR A KINDLE MOBI BOOK","\u002Fblog\u002Fhow-to-add-a-cover-to-an-epub-pdf-or-a-kindle-mobi-book","EPUB, PDF and Kindle MOBI books converted from other formats or downloaded from torrent sites are sometimes cover-missing, which inevitably makes the whole eBook-reading journey less satisfactory",[361,362],"technology","tips",{"title":364,"path":365,"description":366,"tags":367},"How to lint staged Git files","\u002Fblog\u002Fhow-to-lint-staged-git-files","We use linting to automate code formatting issues, to fix syntax errors and coding style. For example, you may have forgotten a semi-colon during aor bug fix you may have accidentally left a console.log statement.",[16,17],{"title":369,"path":370,"description":371,"tags":372},"HOW TO MAKE AJAX CALLS IN JQUERY","\u002Fblog\u002Fhow-to-make-ajax-calls-in-jquery","There are more than one way to make AJAX calls in jQuery. In this tutorial, let’s compare these methods as well as inspect the AJAX calls with Firebug.",[16,17],{"title":374,"path":375,"description":376,"tags":377},"HOW TO USE TELEPHOTO LENSES","\u002Fblog\u002Fhow-to-use-telephoto-lenses","Telephoto lenses are useful for wildlife and landscape photography, given their ability to enlarge distant subjects, but they’re also great for giving your photo an artistic look.",[89],{"title":379,"path":380,"description":381,"tags":382},"HTML INTRODUCTION","\u002Fblog\u002Fhtml-introduction","The language of a webpage is HTML. HTML allows you to take a plain text document created in any simple text editor and organize it into lists, link to other webpages, including images, and more.",[16,383],"html",{"title":385,"path":386,"description":387,"tags":388},"HTML5 API – LOCAL STORAGE, GEOLOCATION & OFFLINE CACHE MANIFEST","\u002Fblog\u002Fhtml5-api-local-storage-geolocation-offline-cache-manifest","Local storage is more secure, and large amounts of data can be stored locally, without affecting website performance. Unlike cookies, the storage limit is far larger (at least 5MB) and information is never transferred to the server.",[16,17],{"title":390,"path":391,"description":392,"tags":393},"HTML5 ELEMENTS","\u002Fblog\u002Fhtml5-elements","HTML5 offers new elements for improving semantics of code as well as better document structure. These elements could now be used to replace traditional HTML code like \u003Cdiv id=”nav”> \u003Cdiv class=”header”> \u003Cdiv id=”footer”>",[16,383],{"title":395,"path":396,"description":397,"tags":398},"HTML5 INTRODUCTION","\u002Fblog\u002Fhtml5-introduction","HTML5 is the latest HTML standard. It walks hand in hand with CSS3, the latest CSS standard.",[16,17],{"title":400,"path":401,"description":402,"tags":403},"HTTP2: NEW FEATURES","\u002Fblog\u002Fhttp2-new-features","HTTP\u002F2 (originally named HTTP\u002F2.0) is the second major version of the HTTP network protocol used by the World Wide Web.",[16,404],"http2",{"title":406,"path":407,"description":408,"tags":409},"IMMUTABLE.JS","\u002Fblog\u002Fimmutable-js","Immutable.js is a library from Facebook which provides immutable data structures and utilities that we can introduce to our applications",[16,17],{"title":411,"path":412,"description":413,"tags":414},"Improve JavaScript Performance with Tree Shaking","\u002Fblog\u002Fimprove-javascript-performance-with-treeshaking","Tree shaking is the process used by bundlers like Webpack for dead-code elimination in JavaScript.",[16,17],{"title":416,"path":417,"description":418,"tags":419},"Improving JavaScript Performance for Web","\u002Fblog\u002Fimproving-javascript-performance-for-web","JavaScript optimisation is becoming increasingly necessary for improving application performance. Let’s look at some of the challenges associated with JavaScript and how to optimise performance.",[16,17,303],{"title":421,"path":422,"description":423,"tags":424},"Improving Next.js Performance","\u002Fblog\u002Fimproving-next-js-performance","Next.js is a zero-config React framework for building server-side and static web applications bundled with enhanced developer experience with features for products such as smart bundling, TypeScript support, route pre-fetching, hybrid static & server rendering, and more.",[16,17,425,303],"nextjs",{"title":427,"path":428,"description":429,"tags":430},"INDEXEDDB","\u002Fblog\u002Findexeddb","IndexedDB stands for Indexed Database, is a web standard for storing large amounts of client-side data in a structured manner. This low-level API is able to index data which enables performance rich search on data.",[16,17,431],"indexeddb",{"title":433,"path":434,"description":435,"tags":436},"INSTALL D-LINK DWA-125 WIRELESS DRIVER ON LINUX","\u002Fblog\u002Finstall-d-link-dwa-125-wireless-driver-on-linux","'If you have recently bought a D-Link Wireless Adapter (DWA-125) for your Linux machine and wondering how to get it working, this article might help you get started.",[361,362],{"title":438,"path":439,"description":440,"tags":441},"INSTALLING NODE.JS","\u002Fblog\u002Finstalling-node-js","In this article we are discussing how to get Node.js working on OSX along with npm, the package manager for node.",[16,17,442],"node.js",{"title":444,"path":445,"description":446,"tags":447},"INTEROPERABLE CSS","\u002Fblog\u002Finteroperable-css","Interoperable CSS or ICSS is a low-level file format that enables CSS Modules, designed for loader implementers (not for end users).",[16,29],{"title":449,"path":450,"description":451,"tags":452},"INTRODUCTION TO D3","\u002Fblog\u002Fintroduction-to-d3","D3 is a data visualization library written in JavaScript. It stands for Data-Driven Documents where Document stand for the DOM or the Docucment Object Model of a wweb page.",[16,17,453],"d3",{"title":455,"path":456,"description":457,"tags":458},"INTRODUCTION TO EMBER.JS","\u002Fblog\u002Fintroduction-to-ember-js","Ember.js is a JavaScript web application framework based on the MVC architectural pattern. It allows developers to create scalable single-page applications by incorporating common idioms and best practices into a framework that provides a rich object model, declarative two-way data binding, computed properties, automatically-updating templates powered by Handlebars.js, and a router for managing application state.",[16,17,173],{"title":460,"path":461,"description":462,"tags":463},"INTRODUCTION TO GULP","\u002Fblog\u002Fintroduction-to-gulp","Gulp is a JavaScript task runner. It’s an alternative to Grunt, which allowed you to define your tasks using JavaScript inside of a file called Gruntfile.js. In this tutorial, I’ll show you how to install Gulp and create a simple configuration file to get your feet wet with this great new task runner.",[16,17,83],{"title":465,"path":466,"description":467,"tags":468},"INTRODUCTION TO HAPI","\u002Fblog\u002Fintroduction-to-hapi","Created by Eran Hammer, hapi.js is an open source framework built on top of Node.js for building web applications and services by Wallmart. In this tutorial, we will go through the advantages of hapi and build a simple application using hapi as the server.",[16,17,442],{"title":470,"path":471,"description":472,"tags":473},"INTRODUCTION TO WEBPACK","\u002Fblog\u002Fintroduction-to-webpack","Webpack is a module bundler. Webpack takes modules with dependencies and generates static assets representing those modules.",[16,17,140],{"title":475,"path":476,"description":477,"tags":478},"ios-7-design-guidelines","\u002Fblog\u002Fios-7-design-guidelines","With the release of iOS 7 design guidelines, app designers and developers will have to adjust the language to match the new \"flat\" design of iOS. In addition to the grid system, the dimensions of icons and commonly used elements, typography and iconography has been updated by Apple in many ways.",[16,9,479],"ios",{"title":481,"path":482,"description":483,"tags":484},"ISO NOISE REDUCTION","\u002Fblog\u002Fiso-noise-reduction","Using great noise reduction is like upgrading your lens. Why do we pay 16x more for one 50mm lens vs. another?",[89],{"title":486,"path":487,"description":488,"tags":489},"ISOMORPHIC JAVASCRIPT","\u002Fblog\u002Fisomorphic-javascript","Isomorphic JavaScript means that we get to share the same code on the client and on the server. So basically, you are rendering your application markup on the server and piping it down as complete HTML to the browser.",[16,17],{"title":491,"path":492,"description":493,"tags":494},"ITCSS","\u002Fblog\u002Fitcss","ITCSS or Inverted Triangle CSS is a meta framework designed to address some common issues around CSS we encounter today. Introduced by Harry Roberts, it is a sane, scalable, managed architecture for CSS.",[16,29],{"title":496,"path":497,"description":498,"tags":499},"JAVASCRIPT ARRAYS","\u002Fblog\u002Fjavascript-arrays","This beginner-level article will discuss further about JavaScript arrays in detail. JavaScript arrays are used to store multiple values in a single variable. JavaScript has an built-in object for manipulating arrays called Array.",[16,17],{"title":501,"path":502,"description":503,"tags":504},"JAVASCRIPT & CLOSURES","\u002Fblog\u002Fjavascript-closures","A closure is an inner function that has access to the outer (enclosing) function’s variables—scope chain.",[16,17],{"title":506,"path":507,"description":508,"tags":509},"JAVASCRIPT CONSOLE","\u002Fblog\u002Fjavascript-console","'The JavaScript Console or the Console Object provides access to the browser’s debugging console.",[16,17],{"title":511,"path":512,"description":513,"tags":514},"JAVASCRIPT & CONSTRUCTOR","\u002Fblog\u002Fjavascript-constructor","ECMAScript is a object based language. An object has a built-in property named constructor.",[16,17],{"title":516,"path":517,"description":518,"tags":519},"JavaScript Design Patterns","\u002Fblog\u002Fjavascript-design-patterns","Design patterns are advanced object-oriented solutions to commonly occurring software problems.  Patterns are about reusable designs and interactions of objects.  Each pattern has a name and becomes part of a vocabulary when discussing complex design solutions.",[16,17,520],"patterns",{"title":522,"path":523,"description":524,"tags":525},"JAVASCRIPT HOISTING AND SCOPE","\u002Fblog\u002Fjavascript-hoisting-and-scope","Hoisting is JavaScript's default behaviour of moving all declarations to the top of the current scope (to the top of the current script or the current function). In different words, a variable can be used before it has been declared.",[16,17],{"title":527,"path":528,"description":529,"tags":530},"JAVASCRIPT & PROTOTYPE","\u002Fblog\u002Fjavascript-prototype","Prototype objects are just simple JavaScript objects and may have their own prototypes. If a prototype has a non-null reference to its prototype, and so on, this is called the prototype chain.",[16,17],{"title":532,"path":533,"description":534,"tags":535},"JELLY BEAN (ANDROID 4.1 SDK) NEW FEATURES","\u002Fblog\u002Fjelly-bean-android-4-1-sdk-new-features","In this article I would like to discuss the new features of Jelly Bean, what has changed from the previous releases, and more.",[361,536],"android",{"title":538,"path":539,"description":540,"tags":541},"JQUERY INTRODUCTION","\u002Fblog\u002Fjquery-introduction","JQuery is a fast, small, and feature-rich JavaScript library. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers.",[16,17,106],{"title":543,"path":544,"description":545,"tags":546},"JQUERY – HOW TO USE","\u002Fblog\u002Fjquery-use","In this article we’ll look at how we can use jquery to manipulate, traverse and select DOM elements at ease. Before we start we have to download jquery and load it in your HTML document",[16,17,106],{"title":548,"path":549,"description":550,"tags":551},"LEXICAL SCOPE","\u002Fblog\u002Flexical-scope","Lexical scope means that scope is defined by author-time decisions of where functions are declared. The lexing phase of compilation is essentially able to know where and how all identifiers are declared, and predict how they will be looked up during execution.",[16,17],{"title":553,"path":554,"description":555,"tags":556},"MAINTAINABLE JAVASCRIPT","\u002Fblog\u002Fmaintainable-javascript","If you are working on a project by your own, you might not worry about the structure, convention and organisation of your code given you fully understand how it works. But working in a team environment it is necessary to make sure that your team members understand your code, easily adaptable and extensible so the importance of maintainable javascript is inevitable.",[16,17],{"title":558,"path":559,"description":560,"tags":561},"MOBILE WEB INTRODUCTION","\u002Fblog\u002Fmobile-web-introduction","What is the mobile web? The mobile web refers to access to the world wide web, i.e. the use of browser-based Internet services, from a handheld mobile device, such as a smartphone or a feature phone, connected to a mobile network or other wireless network.",[16,29,161],{"title":563,"path":564,"description":565,"tags":566},"MODELS & EMBER DATA","\u002Fblog\u002Fmodels-ember-data","If you are thinking of consuming data in your Ember application, you can store them in fixtures. But what if you want to fetch data from a server?",[16,17,173],{"title":568,"path":569,"description":570,"tags":571},".NET FRAMEWORK Q&A","\u002Fblog\u002Fnet-framework-qna","In this article, we are discussing few common .NET frequently asked questions and answers.",[16,572],".net-framework",{"title":574,"path":575,"description":576,"tags":577},"NextJS Client-side, Server-side & Static Rendering","\u002Fblog\u002Fnextjs-client-side-server-side-and-static-rendering","The future of SEO and search ranking algorithms are now in heavy favour of static or server-side rendering. This means building static or server-side rendered apps instantly gain advantages in rankings.",[16,17,425,578],"ssr",{"title":580,"path":581,"description":582,"tags":583},"NODE JS SECURITY","\u002Fblog\u002Fnode-js-security","Node.js has gained momentum in the recent years but there are not many security guidelines available out there.",[16,17],{"title":585,"path":586,"description":587,"tags":588},"NODE.JS – EVENTS","\u002Fblog\u002Fnodejs-events","Many objects in Node emit events: a net.Server emits an event each time a peer connects to it, and fs.readStream emits an event when the file is opened. All objects which emit events are instances of events.EventEmitter.",[16,17,442],{"title":590,"path":591,"description":592,"tags":593},"NODEJS INSTALL WITH NVM","\u002Fblog\u002Fnodejs-install-with-nvm","Node Version Manager is a simple bash script to manage multiple active node.js versions. In this article, we are going to discuss about managing NodeJS install with NVM.",[16,17,442],{"title":595,"path":596,"description":597,"tags":598},"NODE.JS INTRODUCTION","\u002Fblog\u002Fnodejs-introduction","\"Node.js allows you to build scalable network",[16,17,442],{"title":600,"path":601,"description":602,"tags":603},"Node.js Memory Management","\u002Fblog\u002Fnodejs-memory-management","Node.js memory management provides means to dynamically allocate memory chunks for programs when they request them and free it when they are no longer needed, so they can be reused. Application-level memory management can be manual or automatic.",[16,17,442],{"title":605,"path":606,"description":607,"tags":608},"NODEJS PATTERNS","\u002Fblog\u002Fnodejs-patterns","A design pattern is a general, reusable solution to a commonly occurring problem. In this article we are going to look at some common design patterns we can use for Node.js.",[16,442],{"title":610,"path":611,"description":612,"tags":613},"NPM SCRIPTS","\u002Fblog\u002Fnpm-scripts","Task runners like Gulp or Grunt have been go to choice for the front end projects for last few years. Gulp being the latest between the two, and being the popular choice for last couple of years, one might wonder what’s wrong with it.",[16,17,442],{"title":615,"path":616,"description":617,"tags":618},"OPTIMIZING ASP.NET MVC SITES","\u002Fblog\u002Foptimizing-asp-net-mvc-sites","In this article we discuss about four ways of optimizing ASP.NET MVC sites",[16,184,619],"asp.net",{"title":621,"path":622,"description":623,"tags":624},"PHOTOSHOP CC NEW FEATURES","\u002Fblog\u002Fphotoshop-cc-new-features","Adobe Creative Cloud’s Photoshop CC  is packed with new tools and features, as well as some key workflow enhancements.",[9,112],{"title":626,"path":627,"description":628,"tags":629},"POSTCSS","\u002Fblog\u002Fpostcss","PostCSS is a tool for transforming CSS with JavaScript plugins. These plugins can support variables and mixins, transpile future CSS syntax, inline images, and more",[16,29],{"title":631,"path":632,"description":633,"tags":634},"PROPER TAIL CALLS","\u002Fblog\u002Fproper-tail-calls","A tail call happens when a function Foo calls a function Bar as its final action. At that point Foo stops and passes the execution to function Bar and disappears not having to do anything from there onwards.",[16,17],{"title":636,"path":637,"description":638,"tags":639},"PROXIES","\u002Fblog\u002Fproxies","Proxies enable you to intercept and customize actions performed on JavaScript objects such as `getter` and `setter` for getting and setting properties. This is really helpful in scenarios like JSON based API interaction where you have to customize data coming back from the API.",[16,17],{"title":641,"path":642,"description":643,"tags":644},"REACT BEST PRACTICES & PATTERNS","\u002Fblog\u002Freact-best-practices-patterns","In this article we discuss about React best practices & patterns for writing React components, and the recommendations here aim at coding convensions and patterns.",[16,17,140],{"title":646,"path":647,"description":648,"tags":649},"React Component Library with Material UI","\u002Fblog\u002Freact-component-library-with-material-ui","Using Material UI which supports Styled Components is an excellent combination of libraries to start building a design system of your own",[16,17,40,650],"material-ui",{"title":652,"path":653,"description":654,"tags":655},"REACT CONCURRENT MODE","\u002Fblog\u002Freact-concurrent-mode","'Regardless of all the optimizations we do in in React apps, rendering process so far has been a blocking and cannot be interrupted.",[16,40],{"title":657,"path":658,"description":659,"tags":660},"REACT CONTEXT API","\u002Fblog\u002Freact-context-api","The context API will finally become a first-class citizen with the release of React 16.3. Facebook has announced that they are going to release a stable yet revamped version of the context API.",[16,17,40],{"title":662,"path":663,"description":664,"tags":665},"REACT & CSS","\u002Fblog\u002Freact-css","In a scaling project, the way CSS spans out can bring us various problems. Let’s look at these issues, and discuss them in detail.",[16,17],{"title":667,"path":668,"description":669,"tags":670},"REACT DEPLOYMENT","\u002Fblog\u002Freact-deployment","In this article, we are discussing about how to perform a production deployment for React",[16,17,140],{"title":672,"path":673,"description":674,"tags":675},"REACT & ES6","\u002Fblog\u002Freact-es6","ES6 is here and now. So writing React JS components in ES6 will be beneficial considering the new features ES6 brings to us.",[16,17],{"title":677,"path":678,"description":679,"tags":680},"REACT & FLUX","\u002Fblog\u002Freact-flux","Flux is the application architecture that Facebook uses for building client-side web applications. It complements React’s composable view components by utilizing a unidirectional data flow. It’s more of a pattern rather than a formal framework.",[16,17,681],"raect.js",{"title":683,"path":684,"description":685,"tags":686},"REACT & NIGHTWATCH","\u002Fblog\u002Freact-nightwatch","Nightwatch is an end-to-end test framework. The reasons nightwatch is your best choice can be decided upon the reasons described in this article.",[16,17],{"title":688,"path":689,"description":690,"tags":691},"React Re-rendering Components","\u002Fblog\u002Freact-re-rendering-components","React is known for providing a fast user experience by only updating the parts of the UI that have changed. In this article, we discuss how we can optimise the render performance by understanding how React decides to re-render",[16,17,40],{"title":693,"path":694,"description":695,"tags":696},"REACT & REDUX","\u002Fblog\u002Freact-redux","'Redux allows you to manage the state with a minimal API but completely predictable behaviour – a predictable state container for JavaScript apps.",[16,17,140],{"title":698,"path":699,"description":700,"tags":701},"REACT ROUTER","\u002Fblog\u002Freact-router","React Router is the most popular routing library for React, which synchronizes your UI with the URL. It is built on top of React and helps you to build new screens quickly.",[16,17,140],{"title":703,"path":704,"description":705,"tags":706},"REACT STATELESS FUNCTIONAL COMPONENTS","\u002Fblog\u002Freact-stateless-functional-components","React stateless functional components are pure JavaScript functions that only have a render() function and no lifecycle methods like componentDidMount.",[16,17,140],{"title":708,"path":709,"description":710,"tags":711},"REACT V15","\u002Fblog\u002Freact-v15","Facebook released React v15.0.0 on 07\u002F04\u002F2016. The most noticeable change was the version number jump from 0.14 to 15.0.",[16,17,140],{"title":713,"path":714,"description":715,"tags":716},"REDUX & SAGAS","\u002Fblog\u002Fredux-sagas","In reality, for a real world application, just consuming an API end point and displaying the data is not going to cut it.",[16,17,140,717,718],"redux","redux-saga",{"title":720,"path":721,"description":722,"tags":723},"REQUIREJS & HANDLEBARS","\u002Fblog\u002Frequirejs-handlebars","If we are building a web application, code complexity could grow and the app can get bigger. Number of plug-ins can grow bigger, and you will feel the need of adding more modular components. RequireJS can address these issues to increase the speed of your application in an efficient way.",[16,17],{"title":725,"path":726,"description":727,"tags":728},"RESCUING THE DETAILS WITH TOPAZ LABS","\u002Fblog\u002Frescuing-details-topaz-labs","Here are the steps on how to recover shadows and make an image more vibrant with the Topaz Lab’s plug-ins.",[89],{"title":730,"path":731,"description":732,"tags":733},"RUBY API – REST ROUTES, CONSTRAINTS & NAMESPACES","\u002Fblog\u002Fruby-api-rest-routes-constraints-namespaces","In this article, we are going to study REST, routes, constraints, and namespaces. Before we dive into these concepts let’s take a look at how web-based services in the perspective of web users.",[16,124],{"title":735,"path":736,"description":737,"tags":738},"RUBY – INTRODUCTION","\u002Fblog\u002Fruby-introduction","Ruby is a dynamic, reflective, object-oriented, general-purpose programming language. It was designed and developed in the mid-1990s by Yukihiro “Matz” Matsumoto in Japan.",[16,124],{"title":740,"path":741,"description":742,"tags":743},"RUN COMMANDS FOR WINDOWS 7","\u002Fblog\u002Frun-commands-for-windows-7","A run command is the name of the file that starts an application, which is an executable for a program.",[361,744],"windows",{"title":746,"path":747,"description":748,"tags":749},"SAFARI CSS HACKS","\u002Fblog\u002Fsafari-css-hacks","Applying changes only for Safari has been always a challenging task. Also adding the fact that Safari has changed since version 6.1 makes it even harder. In this article we are going to discuss Safari CSS hacks.",[16,29,383],{"title":751,"path":752,"description":753,"tags":754},"SASS CONTROL DIRECTIVES","\u002Fblog\u002Fsass-control-directives","Sass control directives helps creating libraries for reuse and distribution, there by contribute to writing leaner Sass. Advanced frameworks use mixins. These mixins use directives such as @if, @for, each and @while.",[16,17],{"title":756,"path":757,"description":758,"tags":759},"SASS FOR CSS","\u002Fblog\u002Fsass-for-css","Sass is a scripting langauage that is interpreted into CSS. Sass stands for Syntatically Awesome Stylesheets.  Sass consists of two syntaxes. The original syntax, called “the indented syntax”, uses a syntax similar to Haml. It uses indentation to separate code blocks and newline characters to separate rules.",[16,29,292],{"title":761,"path":762,"description":763,"tags":764},"SASS INTRODUCTION","\u002Fblog\u002Fsass-introduction","CSS is crafted to be simple, but over time your styles become large and your files become bloated with selectors growing out of control. Scaling simplicity is difficult.",[16,17],{"title":766,"path":767,"description":768,"tags":769},"SASS – VARIABLES","\u002Fblog\u002Fsass-variables","Native CSS variable support is still in its infancy, but Sass affords us a way to set reusable values.",[16,29,292],{"title":771,"path":772,"description":773,"tags":774},"SECURING YOUR ASP.NET MVC 4 APPLICATION","\u002Fblog\u002Fsecuring-your-asp-net-mvc-4-application","Out of the Box when you create an MVC web site, anyone can post anything to your web site. So we need to control the user access.",[16,184,619],{"title":776,"path":777,"description":778,"tags":779},"SEMANTIC HTML","\u002Fblog\u002Fsemantic-hmtl","Semantic HTML is a way of describing the content of an HTML document, it is not a way of making your page look pretty or visually appealing.",[16,383],{"title":781,"path":782,"description":783,"tags":784},"SEND EMAIL IN UMBRACO","\u002Fblog\u002Fsend-email-in-umbraco","Sending email is a common functionality of any client-facing website. Is it possible to be implemented in Umbraco without a plugin? Yes, and I’m going to demonstrate how to implement such functionality.",[16,785,619],"umbraco",{"title":787,"path":788,"description":789,"tags":790},"Server Side Rendering with Suspense in React 18","\u002Fblog\u002Fserver-side-rendering-with-suspense-in-react-18","React 18 will include architectural improvements to React server-side rendering (SSR) performance.",[16,17,40,578],{"title":792,"path":793,"description":794,"tags":795},"SERVICE WORKERS","\u002Fblog\u002Fservice-workers","Service Worker is a new browser feature which provides event-driven scripts that run independently of web pages. Unlike other workers, Service Workers can be shut down at the end of events, note the lack of retained references from documents, and they have access to domain-wide events such as network fetches.",[16,17,796],"service-worker",{"title":798,"path":799,"description":800,"tags":801},"SETTING UP UMBRACO IN VISUAL STUDIO","\u002Fblog\u002Fsetting-up-umbraco-in-visual-studio","In this article we discuss about setting an Umbraco project with ASP.NET with step by step instructions",[16,619,785],{"title":803,"path":804,"description":805,"tags":806},"Should we declare React functional components with a const or a function?","\u002Fblog\u002Fshould-we-declare-react-functional-components-with-a-const-or-a-function","If you have been writing React functional components for a while now, you may have encountered two ways of declaring a component - an arrow function or a function declaration.",[16,17,807,40],"typesript",{"title":809,"path":810,"description":811,"tags":812},"SMACSS","\u002Fblog\u002Fsmacss","SMACSS stands for Scalable and Modular Architecture for CSS. It is pronounced “smacks” and introduced by Jonathan Snook.",[16,29,292],{"title":814,"path":815,"description":816,"tags":817},"STRUCTURE YOUR SASS","\u002Fblog\u002Fstructure-your-sass","Sass enables your you to separate your stylesheets into individual files, and then you can use the @import directive to include your individual files into one master stylesheet.",[16,29,292],{"title":819,"path":820,"description":821,"tags":822},"STYLUS FOR CSS","\u002Fblog\u002Fstylus-for-css","When your site grows, the CSS can grow along with it, and the maintenance is no longer  trivial. You could break your CSS in to different files and use @import to structure it into one file. But this doesn’t resolve all your architecting and maintenance problems. ",[16,29],{"title":824,"path":825,"description":826,"tags":827},"TAPE & TAP","\u002Fblog\u002Ftape-tap","Tape & Tap are testing tools you can use instead of Mocha or Jasmine. The Test Anything Protocol (TAP) is a definition that has been around since 1987 and Tape is a test harness written in JavaScript for Node and the browser.",[16,17,828],"testing",{"title":830,"path":831,"description":832,"tags":833},"TESTING REACT COMPONENTS WITH ENZYME","\u002Fblog\u002Ftesting-react-components-enzyme","React has become the framework of choice recently within the JavaScript community. And the tools for testing React components has also gained lot of attention.",[16,17,220],{"title":835,"path":836,"description":837,"tags":838},"THE MOST EXPENSIVE CAMERAS IN THE WORLD","\u002Fblog\u002Fthe-most-expensive-cameras-in-the-world","Digital photography has become a hobby that is more and more affordable in recent years, with the increase of hobbyist photographers to serious enthusiasts the camera and lens manufacturers have become competitive and innovative in releasing high specification products.",[89],{"title":840,"path":841,"description":842,"tags":843},"Things to avoid when using React Hooks","\u002Fblog\u002Fthings-to-avoid-when-using-react-hooks","In this article we discuss about a few things to avoid when writing React Hooks and forming good habits through understanding",[16,17,40],{"title":845,"path":846,"description":847,"tags":848},"THINK REACT","\u002Fblog\u002Fthink-react","As we know, React is a library for creating user interfaces. It renders your UI and responds to events aka: the V in MVC. Because it is not as opinionated as many of other front-end JavaScript libraries, it plays nicely with your stack, whatever it maybe, Ruby, Java, Node.js or .NET.",[16,17,140],{"title":850,"path":851,"description":852,"tags":853},"THROTTLE FUNCTION CALLS IN JAVASCRIPT","\u002Fblog\u002Fthrottle-function-calls-in-javascript","If you have written a search component that returns matching result as you type – you would realise that sending a request to the server on every key press is not required as that can result in burdening the server with too many requests.",[16,17],{"title":855,"path":856,"description":857,"tags":858},"Turborepo: The Next Big Thing in Build Systems","\u002Fblog\u002Fturborepo-the-next-big-thing-in-build-systems","Turborepo is a high-performance build system for JavaScript and TypeScript codebases. Vercel who acquired Turborepo claims, through incremental builds, intelligent remote caching, and optimized task scheduling, Turborepo can boost build speeds by 85% or more, enabling teams of all sizes to maintain a fast and efficient build system that scales as codebases and teams grow.",[16,17,859],"nodejs",{"title":861,"path":862,"description":863,"tags":864},"TypeScript Enums vs String Literals","\u002Fblog\u002Ftypescript-enums-vs-string-literals","Enums help to define a set of named constants. Using enums can make it easier to document intent, or create a set of distinct cases.",[16,17,807],{"title":866,"path":867,"description":868,"tags":869},"TypeScript Features You Should No Longer Use","\u002Fblog\u002Ftypescript-features-you-should-no-longer-use","When TypeScript was originally invented by Microsoft in 2010, they implemented features missing from JavaScript at the time including module systems, classes, enums and decorators.",[16,17,870],"typescript",{"title":872,"path":873,"description":874,"tags":875},"Understanding cloneElement, isValidElement and Render Props","\u002Fblog\u002Funderstanding-cloneelement-isvalidelement-and-render-props","React provides several APIs for transforming elements: cloneElement, isValidElement.",[16,17,40],{"title":877,"path":878,"description":879,"tags":880},"UNITS FOR CSS FONT-SIZE","\u002Fblog\u002Funits-for-css-font-size","Fonts sizes in CSS can be measured in four different units adding confusion to the web developer on top of having to deal with different browsers. Which of these four units is the best? Finding a definitive answer is difficult.",[16,29],{"title":882,"path":883,"description":884,"tags":885},"USING ES6 WITH BABEL","\u002Fblog\u002Fusing-es6-babel","Some of the modern browsers are yet to catch up with the new language additions to ES6. This means we have to use Babel to transpile our code into ES5.",[16,17,220],{"title":887,"path":888,"description":889,"tags":890},"VIRTUAL DOM","\u002Fblog\u002Fvirtual-dom","If you are using React, there is a better chance you have heard about virtual DOM. In a nutshell, virtual DOM is an abstract version of the DOM, a lightweight copy of the actual DOM which we can manipulate the way we want and then apply to the DOM tree.",[16,17],{"title":242,"path":892,"description":893,"tags":894},"\u002Fblog\u002Fweb-application-security","'Cyber security has become a necessity for any web developer building client-facing web applications.",[16,895],"security",{"title":897,"path":898,"description":899,"tags":900},"WEB PAGE RENDERING","\u002Fblog\u002Fweb-page-rendering","'Web page rendering is an important subject to study in order to optimize page load times, and to understand how to design solutions to cater for that.",[16,17,29,383],{"title":902,"path":903,"description":904,"tags":905},"WEBPACK EXPORT MODULES","\u002Fblog\u002Fwebpack-export-modules","You may be working in a complex project, where multiple isolated modules need to be imported into a single parent module, you might want to configure Webpack.config to enable exporting modules.",[16,17],{"title":907,"path":908,"description":909,"tags":910},"WHAT IS AGILE PROJECT MANAGEMENT?","\u002Fblog\u002Fwhat-is-agile-project-management","Agile project management allows you to produce a smaller amount of deliverables more frequently and efficiently , making it an excellent choice for the teams that are working in the field of  business analysis, product development, programming , and other areas of collaboration.",[16,911],"agile",{"title":913,"path":914,"description":915,"tags":916},"WRITING FORMS IN REACT AND REDUX","\u002Fblog\u002Fwriting-forms-react","rWiting forms in React and Redux can be challenging, having to deal with forms and fields. In this article we are going to build couple of form using an exisiting library sepcifically for Redux called react-redux-form.",[16,29,383],{"id":918,"title":516,"author":919,"body":920,"date":13715,"description":518,"extension":13716,"image":13717,"meta":13718,"navigation":1086,"path":517,"seo":13719,"stem":13720,"tags":13721,"__hash__":13722},"blog\u002Fblog\u002Fjavascript-design-patterns.md","Sean Amarasinghe",{"type":921,"value":922,"toc":13683},"minimark",[923,933,936,939,942,945,952,957,960,989,993,998,1005,1013,1018,1021,1801,1804,1808,1811,1816,1819,2129,2132,2136,2144,2149,2156,2159,2729,2732,2735,2739,2747,2752,2759,2762,3103,3109,3113,3120,3125,3128,3131,3394,3397,3400,3403,3407,3414,3417,3422,3425,3674,3677,3681,3688,3691,3703,3708,3722,3725,4602,4605,4609,4616,4621,4624,4627,5436,5439,5443,5450,5453,5458,5480,5833,5848,5852,5859,5864,5871,5882,6446,6449,6453,6460,6465,6468,6471,6508,6519,6964,6967,6971,6983,6988,6991,6994,7034,7043,7424,7436,7440,7447,7452,7459,7473,7913,7916,7920,7927,7932,7939,7942,8455,8458,8462,8469,8474,8477,8719,8722,8726,8733,8738,8745,8759,9359,9363,9367,9374,9379,9386,9920,9927,9944,9948,9957,9962,9969,10645,10648,10665,10669,10672,10677,10684,11300,11323,11327,11332,11337,11344,11638,11663,11669,11676,11681,11688,12217,12226,12241,12244,12250,12253,12258,12265,13075,13078,13082,13089,13094,13101,13656,13660,13663,13673,13676,13679],[924,925,926],"blockquote",{},[927,928,929],"p",{},[930,931,932],"em",{},"“Each pattern describes a problem which occurs over and over again … and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without doing it the same way twice.” – Christopher Alexander",[927,934,935],{},"The 23 Gang of Four (GoF) patterns are generally considered the foundation for all other patterns. There are 23 different known design patterns, and they can be separated into three categories by purpose: Creational, Structural, and Behavioral (see below for a complete list).",[927,937,938],{},"C - Creational",[927,940,941],{},"S - Structural",[927,943,944],{},"B - Behavioral",[927,946,947],{},[948,949],"img",{"alt":950,"src":951},"Design patterns categorised for creational, behavioral and structural","\u002Fimages\u002Fblog\u002F2021-12-16-javascript-design-patterns\u002Fdesign-patterns.jpeg",[953,954,956],"h2",{"id":955},"why-design-patterns","Why Design Patterns?",[927,958,959],{},"We already use design patterns every day. They help us solve recurring design problems. But is it necessary to spend time learning them? Let’s look into a few key benefits that design patterns grant us.",[961,962,963,971,977,983],"ul",{},[964,965,966,970],"li",{},[967,968,969],"strong",{},"Do not Repeat Yourself (DRY)"," Patterns help in implementing DRY – this helps to keep our codebase lean.",[964,972,973,976],{},[967,974,975],{},"Reusability"," Code reusability helps to minimise bugs and test functionality in a clean and concise manner. This also helps to improve code readability.",[964,978,979,982],{},[967,980,981],{},"Proven Solutions"," You can be assured that they were revised multiple times and optimizations were probably implemented.",[964,984,985,988],{},[967,986,987],{},"Eases communication:"," When developers are familiar with design patterns, they can more easily communicate with one another about potential solutions to a given problem.",[953,990,992],{"id":991},"creational-design-patterns","Creational Design Patterns",[994,995,997],"h3",{"id":996},"factory-method","Factory Method",[927,999,1000,1001,1004],{},"A Factory Pattern or Factory Method Pattern says that just ",[967,1002,1003],{},"define an interface or abstract class for creating an object but let the subclasses decide which class to instantiate."," In other words, subclasses are responsible to create the instance of the class.",[927,1006,1007,1008,1012],{},"A ",[967,1009,1010],{},[930,1011,997],{}," creates new objects as instructed by the client. One way to create objects in JavaScript is by invoking a constructor function with the new operator. There are maybe scenarios, where the client does not know which one of several candidates objects to instantiate. The Factory Method allows the client to delegate object creation while still retaining control over which type to instantiate.",[927,1014,1015],{},[948,1016],{"alt":997,"src":1017},"\u002Fimages\u002Fblog\u002F2021-12-16-javascript-design-patterns\u002Ffactory-method.png",[927,1019,1020],{},"The factory method will simply set up and return the new object when you call the function. Check out this example:",[1022,1023,1028],"pre",{"className":1024,"code":1025,"language":1026,"meta":1027,"style":1027},"language-jsx shiki shiki-themes github-light github-dark","const VEHICLE_TYPE = {\n  CAR: 'car',\n  VAN: 'van',\n};\n\nconst VEHICLE_COLOR = {\n  WHITE: 'white',\n  SILVER: 'silver',\n  ORANGE: 'orange',\n};\n\nconst VEHICLE_TRANSMISSION = {\n  MANUAL: 'manual',\n  AUTO: 'auto',\n};\n\nclass Car {\n  constructor(options) {\n    this.vehicleType = options.vehicleType;\n    this.doors = options.doors ?? 4;\n    this.transmission = options.transmission ?? VEHICLE_TRANSMISSION.AUTO;\n    this.color = options.color ?? VEHICLE_COLOR.SILVER;\n  }\n}\n\nclass Van {\n  constructor(options) {\n    this.vehicleType = options.vehicleType;\n    this.transmission = options.transmission ?? VEHICLE_TRANSMISSION.MANUAL;\n    this.color = options.color ?? VEHICLE_COLOR.ORANGE;\n  }\n}\n\nclass VehicleFactory {\n  createVehicle(options) {\n    switch (options.vehicleType) {\n      case VEHICLE_TYPE.CAR:\n        this.vehicle = Car;\n        break;\n      case VEHICLE_TYPE.VAN:\n        this.vehicle = Van;\n        break;\n    }\n\n    return new this.vehicle(options);\n  }\n}\n\nconst carFactory = new VehicleFactory();\n\nconst car = carFactory.createVehicle({\n  vehicleType: VEHICLE_TYPE.CAR,\n  color: VEHICLE_COLOR.WHITE,\n  doors: 3,\n});\n\nconst van = carFactory.createVehicle({\n  vehicleType: VEHICLE_TYPE.VAN,\n  color: VEHICLE_COLOR.ORANGE,\n  doors: 5,\n});\n\n\u002F\u002F true\nconsole.log(car.vehicleType === VEHICLE_TYPE.CAR);\n\u002F\u002F { vehicleType: 'car', color: 'white', doors: 5, transmission: 'auto' }\nconsole.log(car);\n\u002F\u002F true\nconsole.log(van.vehicleType === VEHICLE_TYPE.VAN);\n\u002F\u002F { vehicleType: 'van', color: 'orange', doors: 5, transmission: 'manual' }\nconsole.log(van);\n","jsx","",[1029,1030,1031,1051,1064,1075,1081,1088,1100,1111,1122,1133,1138,1143,1155,1166,1177,1182,1187,1199,1215,1230,1252,1277,1301,1307,1313,1318,1328,1339,1350,1372,1394,1399,1404,1409,1419,1431,1440,1456,1470,1478,1492,1504,1511,1517,1522,1542,1547,1552,1557,1574,1579,1598,1613,1629,1640,1646,1651,1667,1680,1693,1703,1708,1713,1720,1744,1750,1760,1765,1785,1791],"code",{"__ignoreMap":1027},[1032,1033,1036,1040,1044,1047],"span",{"class":1034,"line":1035},"line",1,[1032,1037,1039],{"class":1038},"szBVR","const",[1032,1041,1043],{"class":1042},"sj4cs"," VEHICLE_TYPE",[1032,1045,1046],{"class":1038}," =",[1032,1048,1050],{"class":1049},"sVt8B"," {\n",[1032,1052,1054,1057,1061],{"class":1034,"line":1053},2,[1032,1055,1056],{"class":1049},"  CAR: ",[1032,1058,1060],{"class":1059},"sZZnC","'car'",[1032,1062,1063],{"class":1049},",\n",[1032,1065,1067,1070,1073],{"class":1034,"line":1066},3,[1032,1068,1069],{"class":1049},"  VAN: ",[1032,1071,1072],{"class":1059},"'van'",[1032,1074,1063],{"class":1049},[1032,1076,1078],{"class":1034,"line":1077},4,[1032,1079,1080],{"class":1049},"};\n",[1032,1082,1084],{"class":1034,"line":1083},5,[1032,1085,1087],{"emptyLinePlaceholder":1086},true,"\n",[1032,1089,1091,1093,1096,1098],{"class":1034,"line":1090},6,[1032,1092,1039],{"class":1038},[1032,1094,1095],{"class":1042}," VEHICLE_COLOR",[1032,1097,1046],{"class":1038},[1032,1099,1050],{"class":1049},[1032,1101,1103,1106,1109],{"class":1034,"line":1102},7,[1032,1104,1105],{"class":1049},"  WHITE: ",[1032,1107,1108],{"class":1059},"'white'",[1032,1110,1063],{"class":1049},[1032,1112,1114,1117,1120],{"class":1034,"line":1113},8,[1032,1115,1116],{"class":1049},"  SILVER: ",[1032,1118,1119],{"class":1059},"'silver'",[1032,1121,1063],{"class":1049},[1032,1123,1125,1128,1131],{"class":1034,"line":1124},9,[1032,1126,1127],{"class":1049},"  ORANGE: ",[1032,1129,1130],{"class":1059},"'orange'",[1032,1132,1063],{"class":1049},[1032,1134,1136],{"class":1034,"line":1135},10,[1032,1137,1080],{"class":1049},[1032,1139,1141],{"class":1034,"line":1140},11,[1032,1142,1087],{"emptyLinePlaceholder":1086},[1032,1144,1146,1148,1151,1153],{"class":1034,"line":1145},12,[1032,1147,1039],{"class":1038},[1032,1149,1150],{"class":1042}," VEHICLE_TRANSMISSION",[1032,1152,1046],{"class":1038},[1032,1154,1050],{"class":1049},[1032,1156,1158,1161,1164],{"class":1034,"line":1157},13,[1032,1159,1160],{"class":1049},"  MANUAL: ",[1032,1162,1163],{"class":1059},"'manual'",[1032,1165,1063],{"class":1049},[1032,1167,1169,1172,1175],{"class":1034,"line":1168},14,[1032,1170,1171],{"class":1049},"  AUTO: ",[1032,1173,1174],{"class":1059},"'auto'",[1032,1176,1063],{"class":1049},[1032,1178,1180],{"class":1034,"line":1179},15,[1032,1181,1080],{"class":1049},[1032,1183,1185],{"class":1034,"line":1184},16,[1032,1186,1087],{"emptyLinePlaceholder":1086},[1032,1188,1190,1193,1197],{"class":1034,"line":1189},17,[1032,1191,1192],{"class":1038},"class",[1032,1194,1196],{"class":1195},"sScJk"," Car",[1032,1198,1050],{"class":1049},[1032,1200,1202,1205,1208,1212],{"class":1034,"line":1201},18,[1032,1203,1204],{"class":1038},"  constructor",[1032,1206,1207],{"class":1049},"(",[1032,1209,1211],{"class":1210},"s4XuR","options",[1032,1213,1214],{"class":1049},") {\n",[1032,1216,1218,1221,1224,1227],{"class":1034,"line":1217},19,[1032,1219,1220],{"class":1042},"    this",[1032,1222,1223],{"class":1049},".vehicleType ",[1032,1225,1226],{"class":1038},"=",[1032,1228,1229],{"class":1049}," options.vehicleType;\n",[1032,1231,1233,1235,1238,1240,1243,1246,1249],{"class":1034,"line":1232},20,[1032,1234,1220],{"class":1042},[1032,1236,1237],{"class":1049},".doors ",[1032,1239,1226],{"class":1038},[1032,1241,1242],{"class":1049}," options.doors ",[1032,1244,1245],{"class":1038},"??",[1032,1247,1248],{"class":1042}," 4",[1032,1250,1251],{"class":1049},";\n",[1032,1253,1255,1257,1260,1262,1265,1267,1269,1272,1275],{"class":1034,"line":1254},21,[1032,1256,1220],{"class":1042},[1032,1258,1259],{"class":1049},".transmission ",[1032,1261,1226],{"class":1038},[1032,1263,1264],{"class":1049}," options.transmission ",[1032,1266,1245],{"class":1038},[1032,1268,1150],{"class":1042},[1032,1270,1271],{"class":1049},".",[1032,1273,1274],{"class":1042},"AUTO",[1032,1276,1251],{"class":1049},[1032,1278,1280,1282,1285,1287,1290,1292,1294,1296,1299],{"class":1034,"line":1279},22,[1032,1281,1220],{"class":1042},[1032,1283,1284],{"class":1049},".color ",[1032,1286,1226],{"class":1038},[1032,1288,1289],{"class":1049}," options.color ",[1032,1291,1245],{"class":1038},[1032,1293,1095],{"class":1042},[1032,1295,1271],{"class":1049},[1032,1297,1298],{"class":1042},"SILVER",[1032,1300,1251],{"class":1049},[1032,1302,1304],{"class":1034,"line":1303},23,[1032,1305,1306],{"class":1049},"  }\n",[1032,1308,1310],{"class":1034,"line":1309},24,[1032,1311,1312],{"class":1049},"}\n",[1032,1314,1316],{"class":1034,"line":1315},25,[1032,1317,1087],{"emptyLinePlaceholder":1086},[1032,1319,1321,1323,1326],{"class":1034,"line":1320},26,[1032,1322,1192],{"class":1038},[1032,1324,1325],{"class":1195}," Van",[1032,1327,1050],{"class":1049},[1032,1329,1331,1333,1335,1337],{"class":1034,"line":1330},27,[1032,1332,1204],{"class":1038},[1032,1334,1207],{"class":1049},[1032,1336,1211],{"class":1210},[1032,1338,1214],{"class":1049},[1032,1340,1342,1344,1346,1348],{"class":1034,"line":1341},28,[1032,1343,1220],{"class":1042},[1032,1345,1223],{"class":1049},[1032,1347,1226],{"class":1038},[1032,1349,1229],{"class":1049},[1032,1351,1353,1355,1357,1359,1361,1363,1365,1367,1370],{"class":1034,"line":1352},29,[1032,1354,1220],{"class":1042},[1032,1356,1259],{"class":1049},[1032,1358,1226],{"class":1038},[1032,1360,1264],{"class":1049},[1032,1362,1245],{"class":1038},[1032,1364,1150],{"class":1042},[1032,1366,1271],{"class":1049},[1032,1368,1369],{"class":1042},"MANUAL",[1032,1371,1251],{"class":1049},[1032,1373,1375,1377,1379,1381,1383,1385,1387,1389,1392],{"class":1034,"line":1374},30,[1032,1376,1220],{"class":1042},[1032,1378,1284],{"class":1049},[1032,1380,1226],{"class":1038},[1032,1382,1289],{"class":1049},[1032,1384,1245],{"class":1038},[1032,1386,1095],{"class":1042},[1032,1388,1271],{"class":1049},[1032,1390,1391],{"class":1042},"ORANGE",[1032,1393,1251],{"class":1049},[1032,1395,1397],{"class":1034,"line":1396},31,[1032,1398,1306],{"class":1049},[1032,1400,1402],{"class":1034,"line":1401},32,[1032,1403,1312],{"class":1049},[1032,1405,1407],{"class":1034,"line":1406},33,[1032,1408,1087],{"emptyLinePlaceholder":1086},[1032,1410,1412,1414,1417],{"class":1034,"line":1411},34,[1032,1413,1192],{"class":1038},[1032,1415,1416],{"class":1195}," VehicleFactory",[1032,1418,1050],{"class":1049},[1032,1420,1422,1425,1427,1429],{"class":1034,"line":1421},35,[1032,1423,1424],{"class":1195},"  createVehicle",[1032,1426,1207],{"class":1049},[1032,1428,1211],{"class":1210},[1032,1430,1214],{"class":1049},[1032,1432,1434,1437],{"class":1034,"line":1433},36,[1032,1435,1436],{"class":1038},"    switch",[1032,1438,1439],{"class":1049}," (options.vehicleType) {\n",[1032,1441,1443,1446,1448,1450,1453],{"class":1034,"line":1442},37,[1032,1444,1445],{"class":1038},"      case",[1032,1447,1043],{"class":1042},[1032,1449,1271],{"class":1049},[1032,1451,1452],{"class":1042},"CAR",[1032,1454,1455],{"class":1049},":\n",[1032,1457,1459,1462,1465,1467],{"class":1034,"line":1458},38,[1032,1460,1461],{"class":1042},"        this",[1032,1463,1464],{"class":1049},".vehicle ",[1032,1466,1226],{"class":1038},[1032,1468,1469],{"class":1049}," Car;\n",[1032,1471,1473,1476],{"class":1034,"line":1472},39,[1032,1474,1475],{"class":1038},"        break",[1032,1477,1251],{"class":1049},[1032,1479,1481,1483,1485,1487,1490],{"class":1034,"line":1480},40,[1032,1482,1445],{"class":1038},[1032,1484,1043],{"class":1042},[1032,1486,1271],{"class":1049},[1032,1488,1489],{"class":1042},"VAN",[1032,1491,1455],{"class":1049},[1032,1493,1495,1497,1499,1501],{"class":1034,"line":1494},41,[1032,1496,1461],{"class":1042},[1032,1498,1464],{"class":1049},[1032,1500,1226],{"class":1038},[1032,1502,1503],{"class":1049}," Van;\n",[1032,1505,1507,1509],{"class":1034,"line":1506},42,[1032,1508,1475],{"class":1038},[1032,1510,1251],{"class":1049},[1032,1512,1514],{"class":1034,"line":1513},43,[1032,1515,1516],{"class":1049},"    }\n",[1032,1518,1520],{"class":1034,"line":1519},44,[1032,1521,1087],{"emptyLinePlaceholder":1086},[1032,1523,1525,1528,1531,1534,1536,1539],{"class":1034,"line":1524},45,[1032,1526,1527],{"class":1038},"    return",[1032,1529,1530],{"class":1038}," new",[1032,1532,1533],{"class":1042}," this",[1032,1535,1271],{"class":1049},[1032,1537,1538],{"class":1195},"vehicle",[1032,1540,1541],{"class":1049},"(options);\n",[1032,1543,1545],{"class":1034,"line":1544},46,[1032,1546,1306],{"class":1049},[1032,1548,1550],{"class":1034,"line":1549},47,[1032,1551,1312],{"class":1049},[1032,1553,1555],{"class":1034,"line":1554},48,[1032,1556,1087],{"emptyLinePlaceholder":1086},[1032,1558,1560,1562,1565,1567,1569,1571],{"class":1034,"line":1559},49,[1032,1561,1039],{"class":1038},[1032,1563,1564],{"class":1042}," carFactory",[1032,1566,1046],{"class":1038},[1032,1568,1530],{"class":1038},[1032,1570,1416],{"class":1195},[1032,1572,1573],{"class":1049},"();\n",[1032,1575,1577],{"class":1034,"line":1576},50,[1032,1578,1087],{"emptyLinePlaceholder":1086},[1032,1580,1582,1584,1587,1589,1592,1595],{"class":1034,"line":1581},51,[1032,1583,1039],{"class":1038},[1032,1585,1586],{"class":1042}," car",[1032,1588,1046],{"class":1038},[1032,1590,1591],{"class":1049}," carFactory.",[1032,1593,1594],{"class":1195},"createVehicle",[1032,1596,1597],{"class":1049},"({\n",[1032,1599,1601,1604,1607,1609,1611],{"class":1034,"line":1600},52,[1032,1602,1603],{"class":1049},"  vehicleType: ",[1032,1605,1606],{"class":1042},"VEHICLE_TYPE",[1032,1608,1271],{"class":1049},[1032,1610,1452],{"class":1042},[1032,1612,1063],{"class":1049},[1032,1614,1616,1619,1622,1624,1627],{"class":1034,"line":1615},53,[1032,1617,1618],{"class":1049},"  color: ",[1032,1620,1621],{"class":1042},"VEHICLE_COLOR",[1032,1623,1271],{"class":1049},[1032,1625,1626],{"class":1042},"WHITE",[1032,1628,1063],{"class":1049},[1032,1630,1632,1635,1638],{"class":1034,"line":1631},54,[1032,1633,1634],{"class":1049},"  doors: ",[1032,1636,1637],{"class":1042},"3",[1032,1639,1063],{"class":1049},[1032,1641,1643],{"class":1034,"line":1642},55,[1032,1644,1645],{"class":1049},"});\n",[1032,1647,1649],{"class":1034,"line":1648},56,[1032,1650,1087],{"emptyLinePlaceholder":1086},[1032,1652,1654,1656,1659,1661,1663,1665],{"class":1034,"line":1653},57,[1032,1655,1039],{"class":1038},[1032,1657,1658],{"class":1042}," van",[1032,1660,1046],{"class":1038},[1032,1662,1591],{"class":1049},[1032,1664,1594],{"class":1195},[1032,1666,1597],{"class":1049},[1032,1668,1670,1672,1674,1676,1678],{"class":1034,"line":1669},58,[1032,1671,1603],{"class":1049},[1032,1673,1606],{"class":1042},[1032,1675,1271],{"class":1049},[1032,1677,1489],{"class":1042},[1032,1679,1063],{"class":1049},[1032,1681,1683,1685,1687,1689,1691],{"class":1034,"line":1682},59,[1032,1684,1618],{"class":1049},[1032,1686,1621],{"class":1042},[1032,1688,1271],{"class":1049},[1032,1690,1391],{"class":1042},[1032,1692,1063],{"class":1049},[1032,1694,1696,1698,1701],{"class":1034,"line":1695},60,[1032,1697,1634],{"class":1049},[1032,1699,1700],{"class":1042},"5",[1032,1702,1063],{"class":1049},[1032,1704,1706],{"class":1034,"line":1705},61,[1032,1707,1645],{"class":1049},[1032,1709,1711],{"class":1034,"line":1710},62,[1032,1712,1087],{"emptyLinePlaceholder":1086},[1032,1714,1716],{"class":1034,"line":1715},63,[1032,1717,1719],{"class":1718},"sJ8bj","\u002F\u002F true\n",[1032,1721,1723,1726,1729,1732,1735,1737,1739,1741],{"class":1034,"line":1722},64,[1032,1724,1725],{"class":1049},"console.",[1032,1727,1728],{"class":1195},"log",[1032,1730,1731],{"class":1049},"(car.vehicleType ",[1032,1733,1734],{"class":1038},"===",[1032,1736,1043],{"class":1042},[1032,1738,1271],{"class":1049},[1032,1740,1452],{"class":1042},[1032,1742,1743],{"class":1049},");\n",[1032,1745,1747],{"class":1034,"line":1746},65,[1032,1748,1749],{"class":1718},"\u002F\u002F { vehicleType: 'car', color: 'white', doors: 5, transmission: 'auto' }\n",[1032,1751,1753,1755,1757],{"class":1034,"line":1752},66,[1032,1754,1725],{"class":1049},[1032,1756,1728],{"class":1195},[1032,1758,1759],{"class":1049},"(car);\n",[1032,1761,1763],{"class":1034,"line":1762},67,[1032,1764,1719],{"class":1718},[1032,1766,1768,1770,1772,1775,1777,1779,1781,1783],{"class":1034,"line":1767},68,[1032,1769,1725],{"class":1049},[1032,1771,1728],{"class":1195},[1032,1773,1774],{"class":1049},"(van.vehicleType ",[1032,1776,1734],{"class":1038},[1032,1778,1043],{"class":1042},[1032,1780,1271],{"class":1049},[1032,1782,1489],{"class":1042},[1032,1784,1743],{"class":1049},[1032,1786,1788],{"class":1034,"line":1787},69,[1032,1789,1790],{"class":1718},"\u002F\u002F { vehicleType: 'van', color: 'orange', doors: 5, transmission: 'manual' }\n",[1032,1792,1794,1796,1798],{"class":1034,"line":1793},70,[1032,1795,1725],{"class":1049},[1032,1797,1728],{"class":1195},[1032,1799,1800],{"class":1049},"(van);\n",[927,1802,1803],{},"Extensibility is the key objective of the Factory Method. Factory Methods are often used in applications that maintain, manage, or even manipulate different collections of objects but at the same time have many characteristics (i.e. methods and properties) in common. An example would be a collection of documents with a mix of markdown documents, pdf documents, and RTF documents.",[994,1805,1807],{"id":1806},"abstract-factory","Abstract Factory",[927,1809,1810],{},"Abstract Factory creates groups of common objects without specifying their concrete classes. There are situations when we have some of the same types of factories and we want to encapsulate the logic of choice, what of the factories use to a given task.",[927,1812,1813],{},[948,1814],{"alt":1807,"src":1815},"\u002Fimages\u002Fblog\u002F2021-12-16-javascript-design-patterns\u002Fabstract-factory.png",[927,1817,1818],{},"Suppose we have two Abstract Factories whose task is to create vehicles such as cars and vans. One is the Car Factory which creates vehicles that are cars and the other is the Van Factory which creates vehicles that are vans. Both Factories creates vehicles, but they differ in what they do, which is their common theme. This is an implementation of the Abstract Factory pattern.",[1022,1820,1822],{"className":1024,"code":1821,"language":1026,"meta":1027,"style":1027},"class Vehicle {\n  startEngine() {}\n}\n\nclass Car extends Vehicle {\n  startEngine() {\n    console.log('Car: Start engine');\n  }\n}\n\nclass Van extends Vehicle {\n  startEngine() {\n    console.log('Van: Start engine');\n  }\n}\n\nclass VehicleFactory {\n  make() {}\n}\n\nclass CarFactory extends VehicleFactory {\n  makeCar() {\n    console.log('Car created');\n    return new Car();\n  }\n}\n\nclass VanFactory extends VehicleFactory {\n  makeVan() {\n    console.log('Van created');\n    return new Van();\n  }\n}\n\nconst carFactory = new CarFactory();\nconst car = carFactory.makeCar();\ncar.startEngine();\n\nconst vanFactory = new VanFactory();\n",[1029,1823,1824,1833,1841,1845,1849,1862,1869,1883,1887,1891,1895,1907,1913,1926,1930,1934,1938,1946,1953,1957,1961,1974,1981,1994,2004,2008,2012,2016,2029,2036,2049,2059,2063,2067,2071,2085,2100,2110,2114],{"__ignoreMap":1027},[1032,1825,1826,1828,1831],{"class":1034,"line":1035},[1032,1827,1192],{"class":1038},[1032,1829,1830],{"class":1195}," Vehicle",[1032,1832,1050],{"class":1049},[1032,1834,1835,1838],{"class":1034,"line":1053},[1032,1836,1837],{"class":1195},"  startEngine",[1032,1839,1840],{"class":1049},"() {}\n",[1032,1842,1843],{"class":1034,"line":1066},[1032,1844,1312],{"class":1049},[1032,1846,1847],{"class":1034,"line":1077},[1032,1848,1087],{"emptyLinePlaceholder":1086},[1032,1850,1851,1853,1855,1858,1860],{"class":1034,"line":1083},[1032,1852,1192],{"class":1038},[1032,1854,1196],{"class":1195},[1032,1856,1857],{"class":1038}," extends",[1032,1859,1830],{"class":1195},[1032,1861,1050],{"class":1049},[1032,1863,1864,1866],{"class":1034,"line":1090},[1032,1865,1837],{"class":1195},[1032,1867,1868],{"class":1049},"() {\n",[1032,1870,1871,1874,1876,1878,1881],{"class":1034,"line":1102},[1032,1872,1873],{"class":1049},"    console.",[1032,1875,1728],{"class":1195},[1032,1877,1207],{"class":1049},[1032,1879,1880],{"class":1059},"'Car: Start engine'",[1032,1882,1743],{"class":1049},[1032,1884,1885],{"class":1034,"line":1113},[1032,1886,1306],{"class":1049},[1032,1888,1889],{"class":1034,"line":1124},[1032,1890,1312],{"class":1049},[1032,1892,1893],{"class":1034,"line":1135},[1032,1894,1087],{"emptyLinePlaceholder":1086},[1032,1896,1897,1899,1901,1903,1905],{"class":1034,"line":1140},[1032,1898,1192],{"class":1038},[1032,1900,1325],{"class":1195},[1032,1902,1857],{"class":1038},[1032,1904,1830],{"class":1195},[1032,1906,1050],{"class":1049},[1032,1908,1909,1911],{"class":1034,"line":1145},[1032,1910,1837],{"class":1195},[1032,1912,1868],{"class":1049},[1032,1914,1915,1917,1919,1921,1924],{"class":1034,"line":1157},[1032,1916,1873],{"class":1049},[1032,1918,1728],{"class":1195},[1032,1920,1207],{"class":1049},[1032,1922,1923],{"class":1059},"'Van: Start engine'",[1032,1925,1743],{"class":1049},[1032,1927,1928],{"class":1034,"line":1168},[1032,1929,1306],{"class":1049},[1032,1931,1932],{"class":1034,"line":1179},[1032,1933,1312],{"class":1049},[1032,1935,1936],{"class":1034,"line":1184},[1032,1937,1087],{"emptyLinePlaceholder":1086},[1032,1939,1940,1942,1944],{"class":1034,"line":1189},[1032,1941,1192],{"class":1038},[1032,1943,1416],{"class":1195},[1032,1945,1050],{"class":1049},[1032,1947,1948,1951],{"class":1034,"line":1201},[1032,1949,1950],{"class":1195},"  make",[1032,1952,1840],{"class":1049},[1032,1954,1955],{"class":1034,"line":1217},[1032,1956,1312],{"class":1049},[1032,1958,1959],{"class":1034,"line":1232},[1032,1960,1087],{"emptyLinePlaceholder":1086},[1032,1962,1963,1965,1968,1970,1972],{"class":1034,"line":1254},[1032,1964,1192],{"class":1038},[1032,1966,1967],{"class":1195}," CarFactory",[1032,1969,1857],{"class":1038},[1032,1971,1416],{"class":1195},[1032,1973,1050],{"class":1049},[1032,1975,1976,1979],{"class":1034,"line":1279},[1032,1977,1978],{"class":1195},"  makeCar",[1032,1980,1868],{"class":1049},[1032,1982,1983,1985,1987,1989,1992],{"class":1034,"line":1303},[1032,1984,1873],{"class":1049},[1032,1986,1728],{"class":1195},[1032,1988,1207],{"class":1049},[1032,1990,1991],{"class":1059},"'Car created'",[1032,1993,1743],{"class":1049},[1032,1995,1996,1998,2000,2002],{"class":1034,"line":1309},[1032,1997,1527],{"class":1038},[1032,1999,1530],{"class":1038},[1032,2001,1196],{"class":1195},[1032,2003,1573],{"class":1049},[1032,2005,2006],{"class":1034,"line":1315},[1032,2007,1306],{"class":1049},[1032,2009,2010],{"class":1034,"line":1320},[1032,2011,1312],{"class":1049},[1032,2013,2014],{"class":1034,"line":1330},[1032,2015,1087],{"emptyLinePlaceholder":1086},[1032,2017,2018,2020,2023,2025,2027],{"class":1034,"line":1341},[1032,2019,1192],{"class":1038},[1032,2021,2022],{"class":1195}," VanFactory",[1032,2024,1857],{"class":1038},[1032,2026,1416],{"class":1195},[1032,2028,1050],{"class":1049},[1032,2030,2031,2034],{"class":1034,"line":1352},[1032,2032,2033],{"class":1195},"  makeVan",[1032,2035,1868],{"class":1049},[1032,2037,2038,2040,2042,2044,2047],{"class":1034,"line":1374},[1032,2039,1873],{"class":1049},[1032,2041,1728],{"class":1195},[1032,2043,1207],{"class":1049},[1032,2045,2046],{"class":1059},"'Van created'",[1032,2048,1743],{"class":1049},[1032,2050,2051,2053,2055,2057],{"class":1034,"line":1396},[1032,2052,1527],{"class":1038},[1032,2054,1530],{"class":1038},[1032,2056,1325],{"class":1195},[1032,2058,1573],{"class":1049},[1032,2060,2061],{"class":1034,"line":1401},[1032,2062,1306],{"class":1049},[1032,2064,2065],{"class":1034,"line":1406},[1032,2066,1312],{"class":1049},[1032,2068,2069],{"class":1034,"line":1411},[1032,2070,1087],{"emptyLinePlaceholder":1086},[1032,2072,2073,2075,2077,2079,2081,2083],{"class":1034,"line":1421},[1032,2074,1039],{"class":1038},[1032,2076,1564],{"class":1042},[1032,2078,1046],{"class":1038},[1032,2080,1530],{"class":1038},[1032,2082,1967],{"class":1195},[1032,2084,1573],{"class":1049},[1032,2086,2087,2089,2091,2093,2095,2098],{"class":1034,"line":1433},[1032,2088,1039],{"class":1038},[1032,2090,1586],{"class":1042},[1032,2092,1046],{"class":1038},[1032,2094,1591],{"class":1049},[1032,2096,2097],{"class":1195},"makeCar",[1032,2099,1573],{"class":1049},[1032,2101,2102,2105,2108],{"class":1034,"line":1442},[1032,2103,2104],{"class":1049},"car.",[1032,2106,2107],{"class":1195},"startEngine",[1032,2109,1573],{"class":1049},[1032,2111,2112],{"class":1034,"line":1458},[1032,2113,1087],{"emptyLinePlaceholder":1086},[1032,2115,2116,2118,2121,2123,2125,2127],{"class":1034,"line":1472},[1032,2117,1039],{"class":1038},[1032,2119,2120],{"class":1042}," vanFactory",[1032,2122,1046],{"class":1038},[1032,2124,1530],{"class":1038},[1032,2126,2022],{"class":1195},[1032,2128,1573],{"class":1049},[927,2130,2131],{},"Over time the Abstract Factory and Factory Method patterns have merged into a more general pattern called Factory. A Factory is simply an object that creates other objects.",[994,2133,2135],{"id":2134},"builder","Builder",[927,2137,2138,2139,2143],{},"The ",[967,2140,2141],{},[930,2142,2135],{}," is a creational design pattern that allows you to construct a complex object by specifying the type and content only. Construction details are hidden from the client entirely.",[927,2145,2146],{},[948,2147],{"alt":2135,"src":2148},"\u002Fimages\u002Fblog\u002F2021-12-16-javascript-design-patterns\u002Fbuilder.png",[927,2150,2151,2152,2155],{},"The biggest reason for using the Builder pattern is to simplify client code that creates complex objects. The client can still direct the steps taken by the Builder without knowing how the actual work is implemented under the hood. Builders frequently encapsulate the construction of ",[967,2153,2154],{},"Composite objects"," (another GoF design pattern) because the code involved is often complex and repetitive.",[927,2157,2158],{},"Let's look at an example to demonstrate this pattern using a Vehicle Builder class:",[1022,2160,2162],{"className":1024,"code":2161,"language":1026,"meta":1027,"style":1027},"const VEHICLE_TYPE = {\n  CAR: 'car',\n  VAN: 'van',\n};\n\nconst VEHICLE_COLOR = {\n  WHITE: 'white',\n  SILVER: 'silver',\n  ORANGE: 'orange',\n};\n\nconst VEHICLE_TRANSMISSION = {\n  MANUAL: 'manual',\n  AUTO: 'auto',\n};\n\nclass Vehicle {\n  spec() {\n    return `Type: ${this.vehicleType}, \nColor: ${this.color}, \nDoors: ${this.doors},\nTransmission: ${this.transmission}`;\n  }\n}\n\nclass VehicleBuilder {\n  constructor(vehicle = new Vehicle()) {\n    this.vehicle = vehicle;\n    return this;\n  }\n\n  ofType(vehicleType) {\n    this.vehicle.vehicleType = vehicleType;\n    return this;\n  }\n\n  addColor(color) {\n    this.vehicle.color = color;\n    return this;\n  }\n\n  addDoors(doors) {\n    this.vehicle.doors = doors;\n    return this;\n  }\n\n  addTransmission(transmission) {\n    this.vehicle.transmission = transmission;\n    return this;\n  }\n\n  build() {\n    return this.vehicle;\n  }\n}\n\nconst vehicleBuilder = new VehicleBuilder();\n\nconst vehicle = vehicleBuilder\n  .ofType(VEHICLE_TYPE.CAR)\n  .addColor(VEHICLE_COLOR.SILVER)\n  .addDoors(4)\n  .addTransmission(VEHICLE_TRANSMISSION.AUTO)\n  .build();\n\nconsole.log(vehicle.spec());\n",[1029,2163,2164,2174,2182,2190,2194,2198,2208,2216,2224,2232,2236,2240,2250,2258,2266,2270,2274,2282,2289,2307,2321,2336,2353,2357,2361,2365,2374,2391,2402,2410,2414,2418,2429,2441,2449,2453,2457,2468,2480,2488,2492,2496,2507,2519,2527,2531,2535,2546,2558,2566,2570,2574,2581,2590,2594,2598,2602,2617,2621,2633,2652,2669,2683,2701,2710,2714],{"__ignoreMap":1027},[1032,2165,2166,2168,2170,2172],{"class":1034,"line":1035},[1032,2167,1039],{"class":1038},[1032,2169,1043],{"class":1042},[1032,2171,1046],{"class":1038},[1032,2173,1050],{"class":1049},[1032,2175,2176,2178,2180],{"class":1034,"line":1053},[1032,2177,1056],{"class":1049},[1032,2179,1060],{"class":1059},[1032,2181,1063],{"class":1049},[1032,2183,2184,2186,2188],{"class":1034,"line":1066},[1032,2185,1069],{"class":1049},[1032,2187,1072],{"class":1059},[1032,2189,1063],{"class":1049},[1032,2191,2192],{"class":1034,"line":1077},[1032,2193,1080],{"class":1049},[1032,2195,2196],{"class":1034,"line":1083},[1032,2197,1087],{"emptyLinePlaceholder":1086},[1032,2199,2200,2202,2204,2206],{"class":1034,"line":1090},[1032,2201,1039],{"class":1038},[1032,2203,1095],{"class":1042},[1032,2205,1046],{"class":1038},[1032,2207,1050],{"class":1049},[1032,2209,2210,2212,2214],{"class":1034,"line":1102},[1032,2211,1105],{"class":1049},[1032,2213,1108],{"class":1059},[1032,2215,1063],{"class":1049},[1032,2217,2218,2220,2222],{"class":1034,"line":1113},[1032,2219,1116],{"class":1049},[1032,2221,1119],{"class":1059},[1032,2223,1063],{"class":1049},[1032,2225,2226,2228,2230],{"class":1034,"line":1124},[1032,2227,1127],{"class":1049},[1032,2229,1130],{"class":1059},[1032,2231,1063],{"class":1049},[1032,2233,2234],{"class":1034,"line":1135},[1032,2235,1080],{"class":1049},[1032,2237,2238],{"class":1034,"line":1140},[1032,2239,1087],{"emptyLinePlaceholder":1086},[1032,2241,2242,2244,2246,2248],{"class":1034,"line":1145},[1032,2243,1039],{"class":1038},[1032,2245,1150],{"class":1042},[1032,2247,1046],{"class":1038},[1032,2249,1050],{"class":1049},[1032,2251,2252,2254,2256],{"class":1034,"line":1157},[1032,2253,1160],{"class":1049},[1032,2255,1163],{"class":1059},[1032,2257,1063],{"class":1049},[1032,2259,2260,2262,2264],{"class":1034,"line":1168},[1032,2261,1171],{"class":1049},[1032,2263,1174],{"class":1059},[1032,2265,1063],{"class":1049},[1032,2267,2268],{"class":1034,"line":1179},[1032,2269,1080],{"class":1049},[1032,2271,2272],{"class":1034,"line":1184},[1032,2273,1087],{"emptyLinePlaceholder":1086},[1032,2275,2276,2278,2280],{"class":1034,"line":1189},[1032,2277,1192],{"class":1038},[1032,2279,1830],{"class":1195},[1032,2281,1050],{"class":1049},[1032,2283,2284,2287],{"class":1034,"line":1201},[1032,2285,2286],{"class":1195},"  spec",[1032,2288,1868],{"class":1049},[1032,2290,2291,2293,2296,2299,2301,2304],{"class":1034,"line":1217},[1032,2292,1527],{"class":1038},[1032,2294,2295],{"class":1059}," `Type: ${",[1032,2297,2298],{"class":1042},"this",[1032,2300,1271],{"class":1059},[1032,2302,2303],{"class":1049},"vehicleType",[1032,2305,2306],{"class":1059},"}, \n",[1032,2308,2309,2312,2314,2316,2319],{"class":1034,"line":1232},[1032,2310,2311],{"class":1059},"Color: ${",[1032,2313,2298],{"class":1042},[1032,2315,1271],{"class":1059},[1032,2317,2318],{"class":1049},"color",[1032,2320,2306],{"class":1059},[1032,2322,2323,2326,2328,2330,2333],{"class":1034,"line":1254},[1032,2324,2325],{"class":1059},"Doors: ${",[1032,2327,2298],{"class":1042},[1032,2329,1271],{"class":1059},[1032,2331,2332],{"class":1049},"doors",[1032,2334,2335],{"class":1059},"},\n",[1032,2337,2338,2341,2343,2345,2348,2351],{"class":1034,"line":1279},[1032,2339,2340],{"class":1059},"Transmission: ${",[1032,2342,2298],{"class":1042},[1032,2344,1271],{"class":1059},[1032,2346,2347],{"class":1049},"transmission",[1032,2349,2350],{"class":1059},"}`",[1032,2352,1251],{"class":1049},[1032,2354,2355],{"class":1034,"line":1303},[1032,2356,1306],{"class":1049},[1032,2358,2359],{"class":1034,"line":1309},[1032,2360,1312],{"class":1049},[1032,2362,2363],{"class":1034,"line":1315},[1032,2364,1087],{"emptyLinePlaceholder":1086},[1032,2366,2367,2369,2372],{"class":1034,"line":1320},[1032,2368,1192],{"class":1038},[1032,2370,2371],{"class":1195}," VehicleBuilder",[1032,2373,1050],{"class":1049},[1032,2375,2376,2378,2380,2382,2384,2386,2388],{"class":1034,"line":1330},[1032,2377,1204],{"class":1038},[1032,2379,1207],{"class":1049},[1032,2381,1538],{"class":1210},[1032,2383,1046],{"class":1038},[1032,2385,1530],{"class":1038},[1032,2387,1830],{"class":1195},[1032,2389,2390],{"class":1049},"()) {\n",[1032,2392,2393,2395,2397,2399],{"class":1034,"line":1341},[1032,2394,1220],{"class":1042},[1032,2396,1464],{"class":1049},[1032,2398,1226],{"class":1038},[1032,2400,2401],{"class":1049}," vehicle;\n",[1032,2403,2404,2406,2408],{"class":1034,"line":1352},[1032,2405,1527],{"class":1038},[1032,2407,1533],{"class":1042},[1032,2409,1251],{"class":1049},[1032,2411,2412],{"class":1034,"line":1374},[1032,2413,1306],{"class":1049},[1032,2415,2416],{"class":1034,"line":1396},[1032,2417,1087],{"emptyLinePlaceholder":1086},[1032,2419,2420,2423,2425,2427],{"class":1034,"line":1401},[1032,2421,2422],{"class":1195},"  ofType",[1032,2424,1207],{"class":1049},[1032,2426,2303],{"class":1210},[1032,2428,1214],{"class":1049},[1032,2430,2431,2433,2436,2438],{"class":1034,"line":1406},[1032,2432,1220],{"class":1042},[1032,2434,2435],{"class":1049},".vehicle.vehicleType ",[1032,2437,1226],{"class":1038},[1032,2439,2440],{"class":1049}," vehicleType;\n",[1032,2442,2443,2445,2447],{"class":1034,"line":1411},[1032,2444,1527],{"class":1038},[1032,2446,1533],{"class":1042},[1032,2448,1251],{"class":1049},[1032,2450,2451],{"class":1034,"line":1421},[1032,2452,1306],{"class":1049},[1032,2454,2455],{"class":1034,"line":1433},[1032,2456,1087],{"emptyLinePlaceholder":1086},[1032,2458,2459,2462,2464,2466],{"class":1034,"line":1442},[1032,2460,2461],{"class":1195},"  addColor",[1032,2463,1207],{"class":1049},[1032,2465,2318],{"class":1210},[1032,2467,1214],{"class":1049},[1032,2469,2470,2472,2475,2477],{"class":1034,"line":1458},[1032,2471,1220],{"class":1042},[1032,2473,2474],{"class":1049},".vehicle.color ",[1032,2476,1226],{"class":1038},[1032,2478,2479],{"class":1049}," color;\n",[1032,2481,2482,2484,2486],{"class":1034,"line":1472},[1032,2483,1527],{"class":1038},[1032,2485,1533],{"class":1042},[1032,2487,1251],{"class":1049},[1032,2489,2490],{"class":1034,"line":1480},[1032,2491,1306],{"class":1049},[1032,2493,2494],{"class":1034,"line":1494},[1032,2495,1087],{"emptyLinePlaceholder":1086},[1032,2497,2498,2501,2503,2505],{"class":1034,"line":1506},[1032,2499,2500],{"class":1195},"  addDoors",[1032,2502,1207],{"class":1049},[1032,2504,2332],{"class":1210},[1032,2506,1214],{"class":1049},[1032,2508,2509,2511,2514,2516],{"class":1034,"line":1513},[1032,2510,1220],{"class":1042},[1032,2512,2513],{"class":1049},".vehicle.doors ",[1032,2515,1226],{"class":1038},[1032,2517,2518],{"class":1049}," doors;\n",[1032,2520,2521,2523,2525],{"class":1034,"line":1519},[1032,2522,1527],{"class":1038},[1032,2524,1533],{"class":1042},[1032,2526,1251],{"class":1049},[1032,2528,2529],{"class":1034,"line":1524},[1032,2530,1306],{"class":1049},[1032,2532,2533],{"class":1034,"line":1544},[1032,2534,1087],{"emptyLinePlaceholder":1086},[1032,2536,2537,2540,2542,2544],{"class":1034,"line":1549},[1032,2538,2539],{"class":1195},"  addTransmission",[1032,2541,1207],{"class":1049},[1032,2543,2347],{"class":1210},[1032,2545,1214],{"class":1049},[1032,2547,2548,2550,2553,2555],{"class":1034,"line":1554},[1032,2549,1220],{"class":1042},[1032,2551,2552],{"class":1049},".vehicle.transmission ",[1032,2554,1226],{"class":1038},[1032,2556,2557],{"class":1049}," transmission;\n",[1032,2559,2560,2562,2564],{"class":1034,"line":1559},[1032,2561,1527],{"class":1038},[1032,2563,1533],{"class":1042},[1032,2565,1251],{"class":1049},[1032,2567,2568],{"class":1034,"line":1576},[1032,2569,1306],{"class":1049},[1032,2571,2572],{"class":1034,"line":1581},[1032,2573,1087],{"emptyLinePlaceholder":1086},[1032,2575,2576,2579],{"class":1034,"line":1600},[1032,2577,2578],{"class":1195},"  build",[1032,2580,1868],{"class":1049},[1032,2582,2583,2585,2587],{"class":1034,"line":1615},[1032,2584,1527],{"class":1038},[1032,2586,1533],{"class":1042},[1032,2588,2589],{"class":1049},".vehicle;\n",[1032,2591,2592],{"class":1034,"line":1631},[1032,2593,1306],{"class":1049},[1032,2595,2596],{"class":1034,"line":1642},[1032,2597,1312],{"class":1049},[1032,2599,2600],{"class":1034,"line":1648},[1032,2601,1087],{"emptyLinePlaceholder":1086},[1032,2603,2604,2606,2609,2611,2613,2615],{"class":1034,"line":1653},[1032,2605,1039],{"class":1038},[1032,2607,2608],{"class":1042}," vehicleBuilder",[1032,2610,1046],{"class":1038},[1032,2612,1530],{"class":1038},[1032,2614,2371],{"class":1195},[1032,2616,1573],{"class":1049},[1032,2618,2619],{"class":1034,"line":1669},[1032,2620,1087],{"emptyLinePlaceholder":1086},[1032,2622,2623,2625,2628,2630],{"class":1034,"line":1682},[1032,2624,1039],{"class":1038},[1032,2626,2627],{"class":1042}," vehicle",[1032,2629,1046],{"class":1038},[1032,2631,2632],{"class":1049}," vehicleBuilder\n",[1032,2634,2635,2638,2641,2643,2645,2647,2649],{"class":1034,"line":1695},[1032,2636,2637],{"class":1049},"  .",[1032,2639,2640],{"class":1195},"ofType",[1032,2642,1207],{"class":1049},[1032,2644,1606],{"class":1042},[1032,2646,1271],{"class":1049},[1032,2648,1452],{"class":1042},[1032,2650,2651],{"class":1049},")\n",[1032,2653,2654,2656,2659,2661,2663,2665,2667],{"class":1034,"line":1705},[1032,2655,2637],{"class":1049},[1032,2657,2658],{"class":1195},"addColor",[1032,2660,1207],{"class":1049},[1032,2662,1621],{"class":1042},[1032,2664,1271],{"class":1049},[1032,2666,1298],{"class":1042},[1032,2668,2651],{"class":1049},[1032,2670,2671,2673,2676,2678,2681],{"class":1034,"line":1710},[1032,2672,2637],{"class":1049},[1032,2674,2675],{"class":1195},"addDoors",[1032,2677,1207],{"class":1049},[1032,2679,2680],{"class":1042},"4",[1032,2682,2651],{"class":1049},[1032,2684,2685,2687,2690,2692,2695,2697,2699],{"class":1034,"line":1715},[1032,2686,2637],{"class":1049},[1032,2688,2689],{"class":1195},"addTransmission",[1032,2691,1207],{"class":1049},[1032,2693,2694],{"class":1042},"VEHICLE_TRANSMISSION",[1032,2696,1271],{"class":1049},[1032,2698,1274],{"class":1042},[1032,2700,2651],{"class":1049},[1032,2702,2703,2705,2708],{"class":1034,"line":1722},[1032,2704,2637],{"class":1049},[1032,2706,2707],{"class":1195},"build",[1032,2709,1573],{"class":1049},[1032,2711,2712],{"class":1034,"line":1746},[1032,2713,1087],{"emptyLinePlaceholder":1086},[1032,2715,2716,2718,2720,2723,2726],{"class":1034,"line":1752},[1032,2717,1725],{"class":1049},[1032,2719,1728],{"class":1195},[1032,2721,2722],{"class":1049},"(vehicle.",[1032,2724,2725],{"class":1195},"spec",[1032,2727,2728],{"class":1049},"());\n",[927,2730,2731],{},"The code above has a Vehicle (the Director) and a builder object: VehicleBuilder. The Vehicle's construct method accepts a Builder instance which it then takes through a series of assembly steps: ofType, addColor, and addTransmission. The Builder's get method returns the newly assembled product (Vehicle).",[927,2733,2734],{},"Usually it is the last step (build) that returns the newly created object which makes it easy for a Builder to participate in fluent interfaces in which multiple method calls, separated by dot operators, are chained together.",[994,2736,2738],{"id":2737},"prototype","Prototype",[927,2740,2741,2742,2746],{},"The ",[967,2743,2744],{},[930,2745,2738],{}," is a creational design pattern that is used when the type of objects to create is determined by a prototypical instance, which is cloned to produce new objects.",[927,2748,2749],{},[948,2750],{"alt":2738,"src":2751},"\u002Fimages\u002Fblog\u002F2021-12-16-javascript-design-patterns\u002Fprototype.png",[927,2753,2138,2754,2758],{},[967,2755,2756],{},[930,2757,2738],{}," Pattern creates new objects that are initialized with values it copied from a prototype. JavaScript being a prototypal language uses this pattern for creating new objects and their prototypes.",[927,2760,2761],{},"An example of where the Prototype pattern is useful is the initialization of business objects with values that match the default values in the database. The prototype object holds the default values that are copied over into a newly created business object.",[1022,2763,2765],{"className":1024,"code":2764,"language":1026,"meta":1027,"style":1027},"const VEHICLE_TYPE = {\n  CAR: 'car',\n  VAN: 'van',\n};\n\nclass Vehicle {\n  constructor(vehicleType, model) {\n    this.vehicleType = vehicleType;\n    this.model = model;\n  }\n\n  spec() {\n    console.log(`Type: ${this.vehicleType}, model: ${this.model}`);\n  }\n\n  clone() {\n    return new Vehicle(this.vehicleType, this.model);\n  }\n\n  setVehicleType(vehicleType) {\n    this.vehicleType = vehicleType;\n  }\n\n  setModel(model) {\n    this.model = model;\n  }\n}\n\nconst car = new Vehicle(VEHICLE_TYPE.CAR, 'X3');\ncar.spec();\n\nconst van = car.clone();\nvan.spec();\n\nvan.setVehicleType(VEHICLE_TYPE.VAN);\nvan.setModel('X10');\nvan.spec();\n",[1029,2766,2767,2777,2785,2793,2797,2801,2809,2825,2835,2847,2851,2855,2861,2891,2895,2899,2906,2926,2930,2934,2945,2955,2959,2963,2974,2984,2988,2992,2996,3023,3031,3035,3051,3060,3064,3081,3095],{"__ignoreMap":1027},[1032,2768,2769,2771,2773,2775],{"class":1034,"line":1035},[1032,2770,1039],{"class":1038},[1032,2772,1043],{"class":1042},[1032,2774,1046],{"class":1038},[1032,2776,1050],{"class":1049},[1032,2778,2779,2781,2783],{"class":1034,"line":1053},[1032,2780,1056],{"class":1049},[1032,2782,1060],{"class":1059},[1032,2784,1063],{"class":1049},[1032,2786,2787,2789,2791],{"class":1034,"line":1066},[1032,2788,1069],{"class":1049},[1032,2790,1072],{"class":1059},[1032,2792,1063],{"class":1049},[1032,2794,2795],{"class":1034,"line":1077},[1032,2796,1080],{"class":1049},[1032,2798,2799],{"class":1034,"line":1083},[1032,2800,1087],{"emptyLinePlaceholder":1086},[1032,2802,2803,2805,2807],{"class":1034,"line":1090},[1032,2804,1192],{"class":1038},[1032,2806,1830],{"class":1195},[1032,2808,1050],{"class":1049},[1032,2810,2811,2813,2815,2817,2820,2823],{"class":1034,"line":1102},[1032,2812,1204],{"class":1038},[1032,2814,1207],{"class":1049},[1032,2816,2303],{"class":1210},[1032,2818,2819],{"class":1049},", ",[1032,2821,2822],{"class":1210},"model",[1032,2824,1214],{"class":1049},[1032,2826,2827,2829,2831,2833],{"class":1034,"line":1113},[1032,2828,1220],{"class":1042},[1032,2830,1223],{"class":1049},[1032,2832,1226],{"class":1038},[1032,2834,2440],{"class":1049},[1032,2836,2837,2839,2842,2844],{"class":1034,"line":1124},[1032,2838,1220],{"class":1042},[1032,2840,2841],{"class":1049},".model ",[1032,2843,1226],{"class":1038},[1032,2845,2846],{"class":1049}," model;\n",[1032,2848,2849],{"class":1034,"line":1135},[1032,2850,1306],{"class":1049},[1032,2852,2853],{"class":1034,"line":1140},[1032,2854,1087],{"emptyLinePlaceholder":1086},[1032,2856,2857,2859],{"class":1034,"line":1145},[1032,2858,2286],{"class":1195},[1032,2860,1868],{"class":1049},[1032,2862,2863,2865,2867,2869,2872,2874,2876,2878,2881,2883,2885,2887,2889],{"class":1034,"line":1157},[1032,2864,1873],{"class":1049},[1032,2866,1728],{"class":1195},[1032,2868,1207],{"class":1049},[1032,2870,2871],{"class":1059},"`Type: ${",[1032,2873,2298],{"class":1042},[1032,2875,1271],{"class":1059},[1032,2877,2303],{"class":1049},[1032,2879,2880],{"class":1059},"}, model: ${",[1032,2882,2298],{"class":1042},[1032,2884,1271],{"class":1059},[1032,2886,2822],{"class":1049},[1032,2888,2350],{"class":1059},[1032,2890,1743],{"class":1049},[1032,2892,2893],{"class":1034,"line":1168},[1032,2894,1306],{"class":1049},[1032,2896,2897],{"class":1034,"line":1179},[1032,2898,1087],{"emptyLinePlaceholder":1086},[1032,2900,2901,2904],{"class":1034,"line":1184},[1032,2902,2903],{"class":1195},"  clone",[1032,2905,1868],{"class":1049},[1032,2907,2908,2910,2912,2914,2916,2918,2921,2923],{"class":1034,"line":1189},[1032,2909,1527],{"class":1038},[1032,2911,1530],{"class":1038},[1032,2913,1830],{"class":1195},[1032,2915,1207],{"class":1049},[1032,2917,2298],{"class":1042},[1032,2919,2920],{"class":1049},".vehicleType, ",[1032,2922,2298],{"class":1042},[1032,2924,2925],{"class":1049},".model);\n",[1032,2927,2928],{"class":1034,"line":1201},[1032,2929,1306],{"class":1049},[1032,2931,2932],{"class":1034,"line":1217},[1032,2933,1087],{"emptyLinePlaceholder":1086},[1032,2935,2936,2939,2941,2943],{"class":1034,"line":1232},[1032,2937,2938],{"class":1195},"  setVehicleType",[1032,2940,1207],{"class":1049},[1032,2942,2303],{"class":1210},[1032,2944,1214],{"class":1049},[1032,2946,2947,2949,2951,2953],{"class":1034,"line":1254},[1032,2948,1220],{"class":1042},[1032,2950,1223],{"class":1049},[1032,2952,1226],{"class":1038},[1032,2954,2440],{"class":1049},[1032,2956,2957],{"class":1034,"line":1279},[1032,2958,1306],{"class":1049},[1032,2960,2961],{"class":1034,"line":1303},[1032,2962,1087],{"emptyLinePlaceholder":1086},[1032,2964,2965,2968,2970,2972],{"class":1034,"line":1309},[1032,2966,2967],{"class":1195},"  setModel",[1032,2969,1207],{"class":1049},[1032,2971,2822],{"class":1210},[1032,2973,1214],{"class":1049},[1032,2975,2976,2978,2980,2982],{"class":1034,"line":1315},[1032,2977,1220],{"class":1042},[1032,2979,2841],{"class":1049},[1032,2981,1226],{"class":1038},[1032,2983,2846],{"class":1049},[1032,2985,2986],{"class":1034,"line":1320},[1032,2987,1306],{"class":1049},[1032,2989,2990],{"class":1034,"line":1330},[1032,2991,1312],{"class":1049},[1032,2993,2994],{"class":1034,"line":1341},[1032,2995,1087],{"emptyLinePlaceholder":1086},[1032,2997,2998,3000,3002,3004,3006,3008,3010,3012,3014,3016,3018,3021],{"class":1034,"line":1352},[1032,2999,1039],{"class":1038},[1032,3001,1586],{"class":1042},[1032,3003,1046],{"class":1038},[1032,3005,1530],{"class":1038},[1032,3007,1830],{"class":1195},[1032,3009,1207],{"class":1049},[1032,3011,1606],{"class":1042},[1032,3013,1271],{"class":1049},[1032,3015,1452],{"class":1042},[1032,3017,2819],{"class":1049},[1032,3019,3020],{"class":1059},"'X3'",[1032,3022,1743],{"class":1049},[1032,3024,3025,3027,3029],{"class":1034,"line":1374},[1032,3026,2104],{"class":1049},[1032,3028,2725],{"class":1195},[1032,3030,1573],{"class":1049},[1032,3032,3033],{"class":1034,"line":1396},[1032,3034,1087],{"emptyLinePlaceholder":1086},[1032,3036,3037,3039,3041,3043,3046,3049],{"class":1034,"line":1401},[1032,3038,1039],{"class":1038},[1032,3040,1658],{"class":1042},[1032,3042,1046],{"class":1038},[1032,3044,3045],{"class":1049}," car.",[1032,3047,3048],{"class":1195},"clone",[1032,3050,1573],{"class":1049},[1032,3052,3053,3056,3058],{"class":1034,"line":1406},[1032,3054,3055],{"class":1049},"van.",[1032,3057,2725],{"class":1195},[1032,3059,1573],{"class":1049},[1032,3061,3062],{"class":1034,"line":1411},[1032,3063,1087],{"emptyLinePlaceholder":1086},[1032,3065,3066,3068,3071,3073,3075,3077,3079],{"class":1034,"line":1421},[1032,3067,3055],{"class":1049},[1032,3069,3070],{"class":1195},"setVehicleType",[1032,3072,1207],{"class":1049},[1032,3074,1606],{"class":1042},[1032,3076,1271],{"class":1049},[1032,3078,1489],{"class":1042},[1032,3080,1743],{"class":1049},[1032,3082,3083,3085,3088,3090,3093],{"class":1034,"line":1433},[1032,3084,3055],{"class":1049},[1032,3086,3087],{"class":1195},"setModel",[1032,3089,1207],{"class":1049},[1032,3091,3092],{"class":1059},"'X10'",[1032,3094,1743],{"class":1049},[1032,3096,3097,3099,3101],{"class":1034,"line":1442},[1032,3098,3055],{"class":1049},[1032,3100,2725],{"class":1195},[1032,3102,1573],{"class":1049},[927,3104,3105,3106,3108],{},"The Prototype pattern delegates the cloning process to the actual objects that are being cloned. The pattern declares a common interface for all objects that support cloning. This interface lets you clone an object without coupling your code to the class of that object. Usually, such an interface contains just a single ",[1029,3107,3048],{}," method.",[994,3110,3112],{"id":3111},"singleton","Singleton",[927,3114,2741,3115,3119],{},[967,3116,3117],{},[930,3118,3112],{}," is a creational design pattern that restricts the instantiation of a class to one “single” instance. This is useful when exactly one object is needed to coordinate actions across the system.",[927,3121,3122],{},[948,3123],{"alt":3112,"src":3124},"\u002Fimages\u002Fblog\u002F2021-12-16-javascript-design-patterns\u002Fsingleton.png",[927,3126,3127],{},"Singletons limit the need for global variables which is particularly important in JavaScript because it reduces the associated risk of name collisions and namespace pollution. The Module pattern is JavaScript's manifestation of the Singleton pattern.",[927,3129,3130],{},"For example, let's create a Singleton Vehicle class:",[1022,3132,3134],{"className":1024,"code":3133,"language":1026,"meta":1027,"style":1027},"const VEHICLE_TYPE = {\n  CAR: 'car',\n  VAN: 'van',\n};\n\nclass Vehicle {\n  constructor(vehicleType) {\n    const instance = this.constructor.instance;\n    if (instance) {\n      return instance;\n    }\n    this.vahicleType = vehicleType;\n    this.constructor.instance = this;\n  }\n\n  spec() {\n    console.log(this.vahicleType);\n  }\n}\n\nconst car1 = new Vehicle(VEHICLE_TYPE.CAR);\nconst car2 = new Vehicle(VEHICLE_TYPE.VAN);\n\nconsole.log(car1 === car2); \u002F\u002F true\nconsole.log(car1.spec()); \u002F\u002F car\nconsole.log(car2.spec()); \u002F\u002F car (not van!)\n",[1029,3135,3136,3146,3154,3162,3166,3170,3178,3188,3208,3216,3224,3228,3239,3256,3260,3264,3270,3283,3287,3291,3295,3318,3341,3345,3361,3378],{"__ignoreMap":1027},[1032,3137,3138,3140,3142,3144],{"class":1034,"line":1035},[1032,3139,1039],{"class":1038},[1032,3141,1043],{"class":1042},[1032,3143,1046],{"class":1038},[1032,3145,1050],{"class":1049},[1032,3147,3148,3150,3152],{"class":1034,"line":1053},[1032,3149,1056],{"class":1049},[1032,3151,1060],{"class":1059},[1032,3153,1063],{"class":1049},[1032,3155,3156,3158,3160],{"class":1034,"line":1066},[1032,3157,1069],{"class":1049},[1032,3159,1072],{"class":1059},[1032,3161,1063],{"class":1049},[1032,3163,3164],{"class":1034,"line":1077},[1032,3165,1080],{"class":1049},[1032,3167,3168],{"class":1034,"line":1083},[1032,3169,1087],{"emptyLinePlaceholder":1086},[1032,3171,3172,3174,3176],{"class":1034,"line":1090},[1032,3173,1192],{"class":1038},[1032,3175,1830],{"class":1195},[1032,3177,1050],{"class":1049},[1032,3179,3180,3182,3184,3186],{"class":1034,"line":1102},[1032,3181,1204],{"class":1038},[1032,3183,1207],{"class":1049},[1032,3185,2303],{"class":1210},[1032,3187,1214],{"class":1049},[1032,3189,3190,3193,3196,3198,3200,3202,3205],{"class":1034,"line":1113},[1032,3191,3192],{"class":1038},"    const",[1032,3194,3195],{"class":1042}," instance",[1032,3197,1046],{"class":1038},[1032,3199,1533],{"class":1042},[1032,3201,1271],{"class":1049},[1032,3203,3204],{"class":1042},"constructor",[1032,3206,3207],{"class":1049},".instance;\n",[1032,3209,3210,3213],{"class":1034,"line":1124},[1032,3211,3212],{"class":1038},"    if",[1032,3214,3215],{"class":1049}," (instance) {\n",[1032,3217,3218,3221],{"class":1034,"line":1135},[1032,3219,3220],{"class":1038},"      return",[1032,3222,3223],{"class":1049}," instance;\n",[1032,3225,3226],{"class":1034,"line":1140},[1032,3227,1516],{"class":1049},[1032,3229,3230,3232,3235,3237],{"class":1034,"line":1145},[1032,3231,1220],{"class":1042},[1032,3233,3234],{"class":1049},".vahicleType ",[1032,3236,1226],{"class":1038},[1032,3238,2440],{"class":1049},[1032,3240,3241,3243,3245,3247,3250,3252,3254],{"class":1034,"line":1157},[1032,3242,1220],{"class":1042},[1032,3244,1271],{"class":1049},[1032,3246,3204],{"class":1042},[1032,3248,3249],{"class":1049},".instance ",[1032,3251,1226],{"class":1038},[1032,3253,1533],{"class":1042},[1032,3255,1251],{"class":1049},[1032,3257,3258],{"class":1034,"line":1168},[1032,3259,1306],{"class":1049},[1032,3261,3262],{"class":1034,"line":1179},[1032,3263,1087],{"emptyLinePlaceholder":1086},[1032,3265,3266,3268],{"class":1034,"line":1184},[1032,3267,2286],{"class":1195},[1032,3269,1868],{"class":1049},[1032,3271,3272,3274,3276,3278,3280],{"class":1034,"line":1189},[1032,3273,1873],{"class":1049},[1032,3275,1728],{"class":1195},[1032,3277,1207],{"class":1049},[1032,3279,2298],{"class":1042},[1032,3281,3282],{"class":1049},".vahicleType);\n",[1032,3284,3285],{"class":1034,"line":1201},[1032,3286,1306],{"class":1049},[1032,3288,3289],{"class":1034,"line":1217},[1032,3290,1312],{"class":1049},[1032,3292,3293],{"class":1034,"line":1232},[1032,3294,1087],{"emptyLinePlaceholder":1086},[1032,3296,3297,3299,3302,3304,3306,3308,3310,3312,3314,3316],{"class":1034,"line":1254},[1032,3298,1039],{"class":1038},[1032,3300,3301],{"class":1042}," car1",[1032,3303,1046],{"class":1038},[1032,3305,1530],{"class":1038},[1032,3307,1830],{"class":1195},[1032,3309,1207],{"class":1049},[1032,3311,1606],{"class":1042},[1032,3313,1271],{"class":1049},[1032,3315,1452],{"class":1042},[1032,3317,1743],{"class":1049},[1032,3319,3320,3322,3325,3327,3329,3331,3333,3335,3337,3339],{"class":1034,"line":1279},[1032,3321,1039],{"class":1038},[1032,3323,3324],{"class":1042}," car2",[1032,3326,1046],{"class":1038},[1032,3328,1530],{"class":1038},[1032,3330,1830],{"class":1195},[1032,3332,1207],{"class":1049},[1032,3334,1606],{"class":1042},[1032,3336,1271],{"class":1049},[1032,3338,1489],{"class":1042},[1032,3340,1743],{"class":1049},[1032,3342,3343],{"class":1034,"line":1303},[1032,3344,1087],{"emptyLinePlaceholder":1086},[1032,3346,3347,3349,3351,3354,3356,3359],{"class":1034,"line":1309},[1032,3348,1725],{"class":1049},[1032,3350,1728],{"class":1195},[1032,3352,3353],{"class":1049},"(car1 ",[1032,3355,1734],{"class":1038},[1032,3357,3358],{"class":1049}," car2); ",[1032,3360,1719],{"class":1718},[1032,3362,3363,3365,3367,3370,3372,3375],{"class":1034,"line":1315},[1032,3364,1725],{"class":1049},[1032,3366,1728],{"class":1195},[1032,3368,3369],{"class":1049},"(car1.",[1032,3371,2725],{"class":1195},[1032,3373,3374],{"class":1049},"()); ",[1032,3376,3377],{"class":1718},"\u002F\u002F car\n",[1032,3379,3380,3382,3384,3387,3389,3391],{"class":1034,"line":1320},[1032,3381,1725],{"class":1049},[1032,3383,1728],{"class":1195},[1032,3385,3386],{"class":1049},"(car2.",[1032,3388,2725],{"class":1195},[1032,3390,3374],{"class":1049},[1032,3392,3393],{"class":1718},"\u002F\u002F car (not van!)\n",[927,3395,3396],{},"Singleton is a manifestation of a common JavaScript pattern called the Module pattern. The module is the basis of all popular JavaScript libraries and frameworks (React, Vue, Angular, etc.)",[953,3398,992],{"id":3399},"creational-design-patterns-1",[927,3401,3402],{},"Behavioral Design Patterns focus on improving the communication between disperate objects in the system.",[953,3404,3406],{"id":3405},"chain-of-responsibility","Chain of Responsibility",[927,3408,2741,3409,3413],{},[967,3410,3411],{},[930,3412,3406],{}," is a behavioral design pattern consisting of a source of command objects and a series of processing objects.",[927,3415,3416],{},"It provides a chain of loosely coupled objects one of which can satisfy a request. This pattern is essentially a linear search for an object that can handle a particular request.",[927,3418,3419],{},[948,3420],{"alt":3406,"src":3421},"\u002Fimages\u002Fblog\u002F2021-12-16-javascript-design-patterns\u002Fchain-of-responsibility.png",[927,3423,3424],{},"The example below demonstrates a solution for dispensing money from an ATM machine. It breaks down the combination of bank notes ($100, $50, $20, $10, $5) that satisfies the request.",[1022,3426,3428],{"className":1024,"code":3427,"language":1026,"meta":1027,"style":1027},"class ATM {\n  constructor(amount) {\n    this.amount = amount;\n    console.log(`Request: $${amount}\\n`);\n  }\n\n  request(bill) {\n    const count = Math.floor(this.amount \u002F bill);\n    this.amount -= count * bill;\n    console.log(`Dispense: ${count} $${bill} bills`);\n\n    return this;\n  }\n}\n\nconst atm = new ATM(425);\n\natm.request(100).request(50).request(20).request(10).request(5);\n",[1029,3429,3430,3439,3450,3462,3486,3490,3494,3506,3533,3551,3575,3579,3587,3591,3595,3599,3619,3623],{"__ignoreMap":1027},[1032,3431,3432,3434,3437],{"class":1034,"line":1035},[1032,3433,1192],{"class":1038},[1032,3435,3436],{"class":1195}," ATM",[1032,3438,1050],{"class":1049},[1032,3440,3441,3443,3445,3448],{"class":1034,"line":1053},[1032,3442,1204],{"class":1038},[1032,3444,1207],{"class":1049},[1032,3446,3447],{"class":1210},"amount",[1032,3449,1214],{"class":1049},[1032,3451,3452,3454,3457,3459],{"class":1034,"line":1066},[1032,3453,1220],{"class":1042},[1032,3455,3456],{"class":1049},".amount ",[1032,3458,1226],{"class":1038},[1032,3460,3461],{"class":1049}," amount;\n",[1032,3463,3464,3466,3468,3470,3473,3475,3478,3481,3484],{"class":1034,"line":1077},[1032,3465,1873],{"class":1049},[1032,3467,1728],{"class":1195},[1032,3469,1207],{"class":1049},[1032,3471,3472],{"class":1059},"`Request: $${",[1032,3474,3447],{"class":1049},[1032,3476,3477],{"class":1059},"}",[1032,3479,3480],{"class":1042},"\\n",[1032,3482,3483],{"class":1059},"`",[1032,3485,1743],{"class":1049},[1032,3487,3488],{"class":1034,"line":1083},[1032,3489,1306],{"class":1049},[1032,3491,3492],{"class":1034,"line":1090},[1032,3493,1087],{"emptyLinePlaceholder":1086},[1032,3495,3496,3499,3501,3504],{"class":1034,"line":1102},[1032,3497,3498],{"class":1195},"  request",[1032,3500,1207],{"class":1049},[1032,3502,3503],{"class":1210},"bill",[1032,3505,1214],{"class":1049},[1032,3507,3508,3510,3513,3515,3518,3521,3523,3525,3527,3530],{"class":1034,"line":1113},[1032,3509,3192],{"class":1038},[1032,3511,3512],{"class":1042}," count",[1032,3514,1046],{"class":1038},[1032,3516,3517],{"class":1049}," Math.",[1032,3519,3520],{"class":1195},"floor",[1032,3522,1207],{"class":1049},[1032,3524,2298],{"class":1042},[1032,3526,3456],{"class":1049},[1032,3528,3529],{"class":1038},"\u002F",[1032,3531,3532],{"class":1049}," bill);\n",[1032,3534,3535,3537,3539,3542,3545,3548],{"class":1034,"line":1124},[1032,3536,1220],{"class":1042},[1032,3538,3456],{"class":1049},[1032,3540,3541],{"class":1038},"-=",[1032,3543,3544],{"class":1049}," count ",[1032,3546,3547],{"class":1038},"*",[1032,3549,3550],{"class":1049}," bill;\n",[1032,3552,3553,3555,3557,3559,3562,3565,3568,3570,3573],{"class":1034,"line":1135},[1032,3554,1873],{"class":1049},[1032,3556,1728],{"class":1195},[1032,3558,1207],{"class":1049},[1032,3560,3561],{"class":1059},"`Dispense: ${",[1032,3563,3564],{"class":1049},"count",[1032,3566,3567],{"class":1059},"} $${",[1032,3569,3503],{"class":1049},[1032,3571,3572],{"class":1059},"} bills`",[1032,3574,1743],{"class":1049},[1032,3576,3577],{"class":1034,"line":1140},[1032,3578,1087],{"emptyLinePlaceholder":1086},[1032,3580,3581,3583,3585],{"class":1034,"line":1145},[1032,3582,1527],{"class":1038},[1032,3584,1533],{"class":1042},[1032,3586,1251],{"class":1049},[1032,3588,3589],{"class":1034,"line":1157},[1032,3590,1306],{"class":1049},[1032,3592,3593],{"class":1034,"line":1168},[1032,3594,1312],{"class":1049},[1032,3596,3597],{"class":1034,"line":1179},[1032,3598,1087],{"emptyLinePlaceholder":1086},[1032,3600,3601,3603,3606,3608,3610,3612,3614,3617],{"class":1034,"line":1184},[1032,3602,1039],{"class":1038},[1032,3604,3605],{"class":1042}," atm",[1032,3607,1046],{"class":1038},[1032,3609,1530],{"class":1038},[1032,3611,3436],{"class":1195},[1032,3613,1207],{"class":1049},[1032,3615,3616],{"class":1042},"425",[1032,3618,1743],{"class":1049},[1032,3620,3621],{"class":1034,"line":1189},[1032,3622,1087],{"emptyLinePlaceholder":1086},[1032,3624,3625,3628,3631,3633,3636,3639,3641,3643,3646,3648,3650,3652,3655,3657,3659,3661,3664,3666,3668,3670,3672],{"class":1034,"line":1201},[1032,3626,3627],{"class":1049},"atm.",[1032,3629,3630],{"class":1195},"request",[1032,3632,1207],{"class":1049},[1032,3634,3635],{"class":1042},"100",[1032,3637,3638],{"class":1049},").",[1032,3640,3630],{"class":1195},[1032,3642,1207],{"class":1049},[1032,3644,3645],{"class":1042},"50",[1032,3647,3638],{"class":1049},[1032,3649,3630],{"class":1195},[1032,3651,1207],{"class":1049},[1032,3653,3654],{"class":1042},"20",[1032,3656,3638],{"class":1049},[1032,3658,3630],{"class":1195},[1032,3660,1207],{"class":1049},[1032,3662,3663],{"class":1042},"10",[1032,3665,3638],{"class":1049},[1032,3667,3630],{"class":1195},[1032,3669,1207],{"class":1049},[1032,3671,1700],{"class":1042},[1032,3673,1743],{"class":1049},[927,3675,3676],{},"An example of the chain of responsibility pattern is event-bubbling in which an event propagates through a series of nested controls one of which may choose to handle the event.",[953,3678,3680],{"id":3679},"command","Command",[927,3682,2741,3683,3687],{},[967,3684,3685],{},[930,3686,3680],{}," pattern is a behavioral design pattern in which an object is used to encapsulate all information needed to perform an action or trigger an event at a later time.",[927,3689,3690],{},"This information includes:",[3692,3693,3694,3697,3700],"ol",{},[964,3695,3696],{},"The method name",[964,3698,3699],{},"The object that owns the method and",[964,3701,3702],{},"Values for the method parameters.",[927,3704,3705],{},[948,3706],{"alt":3680,"src":3707},"\u002Fimages\u002Fblog\u002F2021-12-16-javascript-design-patterns\u002Fcommand.png",[927,3709,2138,3710,3714,3715,3718,3719,1271],{},[967,3711,3712],{},[930,3713,3680],{}," pattern encapsulates actions as objects. Command objects allow for loosely coupled systems by separating the objects that issue a request from the objects that actually process the request. These requests are called ",[967,3716,3717],{},"events"," and the code that processes the requests are called ",[967,3720,3721],{},"event handlers",[927,3723,3724],{},"In our example we have a calculator with 6 operations: add, subtract, multiply, divide, undo and execute. Each operation is encapsulated by a Command object.",[1022,3726,3728],{"className":1024,"code":3727,"language":1026,"meta":1027,"style":1027},"class Calculator {\n  constructor() {\n    this.value = 0;\n    this.history = [];\n  }\n\n  executeCommand(command) {\n    this.value = command.execute(this.value);\n    this.history.push(command);\n  }\n\n  undo() {\n    const command = this.history.pop();\n    this.value = command.undo(this.value);\n  }\n\n  add(value) {\n    this.value = this.value + value;\n  }\n\n  subtract(value) {\n    this.value = this.value - value;\n  }\n\n  multiply(value) {\n    this.value = this.value * value;\n  }\n\n  divide(value) {\n    this.value = this.value \u002F value;\n  }\n}\n\nclass AddCommand {\n  constructor(value) {\n    this.valueToAdd = value;\n  }\n\n  execute(currentValue) {\n    return currentValue + this.valueToAdd;\n  }\n\n  undo(currentValue) {\n    return currentValue - this.valueToAdd;\n  }\n}\n\nclass SubtractCommand {\n  constructor(value) {\n    this.valueToSubtract = value;\n  }\n\n  execute(currentValue) {\n    return currentValue - this.valueToSubtract;\n  }\n\n  undo(currentValue) {\n    return currentValue + this.valueToSubtract;\n  }\n}\n\nclass MultiplyCommand {\n  constructor(value) {\n    this.valueToMultiply = value;\n  }\n\n  execute(currentValue) {\n    return currentValue * this.valueToMultiply;\n  }\n\n  undo(currentValue) {\n    return currentValue \u002F this.valueToMultiply;\n  }\n}\n\nclass DivideCommand {\n  constructor(value) {\n    this.valueToDivide = value;\n  }\n\n  execute(currentValue) {\n    return currentValue \u002F this.valueToDivide;\n  }\n\n  undo(currentValue) {\n    return currentValue * this.valueToDivide;\n  }\n}\n\nconst calculator = new Calculator();\n\ncalculator.executeCommand(new AddCommand(10));\ncalculator.executeCommand(new MultiplyCommand(2));\ncalculator.executeCommand(new SubtractCommand(10));\ncalculator.executeCommand(new DivideCommand(2));\nconsole.log(calculator.value); \u002F\u002F 5\ncalculator.undo();\nconsole.log(calculator.value); \u002F\u002F 10\n",[1029,3729,3730,3739,3745,3759,3771,3775,3779,3790,3811,3824,3828,3832,3839,3857,3876,3880,3884,3896,3914,3918,3922,3933,3950,3954,3958,3969,3985,3989,3993,4004,4020,4024,4028,4032,4041,4051,4062,4066,4070,4082,4096,4100,4104,4114,4126,4130,4134,4138,4147,4157,4168,4172,4176,4186,4199,4203,4207,4217,4229,4233,4237,4241,4250,4260,4271,4275,4279,4289,4302,4306,4310,4321,4334,4339,4344,4349,4359,4370,4382,4387,4392,4403,4417,4422,4427,4438,4451,4456,4461,4466,4482,4487,4510,4530,4549,4568,4581,4590],{"__ignoreMap":1027},[1032,3731,3732,3734,3737],{"class":1034,"line":1035},[1032,3733,1192],{"class":1038},[1032,3735,3736],{"class":1195}," Calculator",[1032,3738,1050],{"class":1049},[1032,3740,3741,3743],{"class":1034,"line":1053},[1032,3742,1204],{"class":1038},[1032,3744,1868],{"class":1049},[1032,3746,3747,3749,3752,3754,3757],{"class":1034,"line":1066},[1032,3748,1220],{"class":1042},[1032,3750,3751],{"class":1049},".value ",[1032,3753,1226],{"class":1038},[1032,3755,3756],{"class":1042}," 0",[1032,3758,1251],{"class":1049},[1032,3760,3761,3763,3766,3768],{"class":1034,"line":1077},[1032,3762,1220],{"class":1042},[1032,3764,3765],{"class":1049},".history ",[1032,3767,1226],{"class":1038},[1032,3769,3770],{"class":1049}," [];\n",[1032,3772,3773],{"class":1034,"line":1083},[1032,3774,1306],{"class":1049},[1032,3776,3777],{"class":1034,"line":1090},[1032,3778,1087],{"emptyLinePlaceholder":1086},[1032,3780,3781,3784,3786,3788],{"class":1034,"line":1102},[1032,3782,3783],{"class":1195},"  executeCommand",[1032,3785,1207],{"class":1049},[1032,3787,3679],{"class":1210},[1032,3789,1214],{"class":1049},[1032,3791,3792,3794,3796,3798,3801,3804,3806,3808],{"class":1034,"line":1113},[1032,3793,1220],{"class":1042},[1032,3795,3751],{"class":1049},[1032,3797,1226],{"class":1038},[1032,3799,3800],{"class":1049}," command.",[1032,3802,3803],{"class":1195},"execute",[1032,3805,1207],{"class":1049},[1032,3807,2298],{"class":1042},[1032,3809,3810],{"class":1049},".value);\n",[1032,3812,3813,3815,3818,3821],{"class":1034,"line":1124},[1032,3814,1220],{"class":1042},[1032,3816,3817],{"class":1049},".history.",[1032,3819,3820],{"class":1195},"push",[1032,3822,3823],{"class":1049},"(command);\n",[1032,3825,3826],{"class":1034,"line":1135},[1032,3827,1306],{"class":1049},[1032,3829,3830],{"class":1034,"line":1140},[1032,3831,1087],{"emptyLinePlaceholder":1086},[1032,3833,3834,3837],{"class":1034,"line":1145},[1032,3835,3836],{"class":1195},"  undo",[1032,3838,1868],{"class":1049},[1032,3840,3841,3843,3846,3848,3850,3852,3855],{"class":1034,"line":1157},[1032,3842,3192],{"class":1038},[1032,3844,3845],{"class":1042}," command",[1032,3847,1046],{"class":1038},[1032,3849,1533],{"class":1042},[1032,3851,3817],{"class":1049},[1032,3853,3854],{"class":1195},"pop",[1032,3856,1573],{"class":1049},[1032,3858,3859,3861,3863,3865,3867,3870,3872,3874],{"class":1034,"line":1168},[1032,3860,1220],{"class":1042},[1032,3862,3751],{"class":1049},[1032,3864,1226],{"class":1038},[1032,3866,3800],{"class":1049},[1032,3868,3869],{"class":1195},"undo",[1032,3871,1207],{"class":1049},[1032,3873,2298],{"class":1042},[1032,3875,3810],{"class":1049},[1032,3877,3878],{"class":1034,"line":1179},[1032,3879,1306],{"class":1049},[1032,3881,3882],{"class":1034,"line":1184},[1032,3883,1087],{"emptyLinePlaceholder":1086},[1032,3885,3886,3889,3891,3894],{"class":1034,"line":1189},[1032,3887,3888],{"class":1195},"  add",[1032,3890,1207],{"class":1049},[1032,3892,3893],{"class":1210},"value",[1032,3895,1214],{"class":1049},[1032,3897,3898,3900,3902,3904,3906,3908,3911],{"class":1034,"line":1201},[1032,3899,1220],{"class":1042},[1032,3901,3751],{"class":1049},[1032,3903,1226],{"class":1038},[1032,3905,1533],{"class":1042},[1032,3907,3751],{"class":1049},[1032,3909,3910],{"class":1038},"+",[1032,3912,3913],{"class":1049}," value;\n",[1032,3915,3916],{"class":1034,"line":1217},[1032,3917,1306],{"class":1049},[1032,3919,3920],{"class":1034,"line":1232},[1032,3921,1087],{"emptyLinePlaceholder":1086},[1032,3923,3924,3927,3929,3931],{"class":1034,"line":1254},[1032,3925,3926],{"class":1195},"  subtract",[1032,3928,1207],{"class":1049},[1032,3930,3893],{"class":1210},[1032,3932,1214],{"class":1049},[1032,3934,3935,3937,3939,3941,3943,3945,3948],{"class":1034,"line":1279},[1032,3936,1220],{"class":1042},[1032,3938,3751],{"class":1049},[1032,3940,1226],{"class":1038},[1032,3942,1533],{"class":1042},[1032,3944,3751],{"class":1049},[1032,3946,3947],{"class":1038},"-",[1032,3949,3913],{"class":1049},[1032,3951,3952],{"class":1034,"line":1303},[1032,3953,1306],{"class":1049},[1032,3955,3956],{"class":1034,"line":1309},[1032,3957,1087],{"emptyLinePlaceholder":1086},[1032,3959,3960,3963,3965,3967],{"class":1034,"line":1315},[1032,3961,3962],{"class":1195},"  multiply",[1032,3964,1207],{"class":1049},[1032,3966,3893],{"class":1210},[1032,3968,1214],{"class":1049},[1032,3970,3971,3973,3975,3977,3979,3981,3983],{"class":1034,"line":1320},[1032,3972,1220],{"class":1042},[1032,3974,3751],{"class":1049},[1032,3976,1226],{"class":1038},[1032,3978,1533],{"class":1042},[1032,3980,3751],{"class":1049},[1032,3982,3547],{"class":1038},[1032,3984,3913],{"class":1049},[1032,3986,3987],{"class":1034,"line":1330},[1032,3988,1306],{"class":1049},[1032,3990,3991],{"class":1034,"line":1341},[1032,3992,1087],{"emptyLinePlaceholder":1086},[1032,3994,3995,3998,4000,4002],{"class":1034,"line":1352},[1032,3996,3997],{"class":1195},"  divide",[1032,3999,1207],{"class":1049},[1032,4001,3893],{"class":1210},[1032,4003,1214],{"class":1049},[1032,4005,4006,4008,4010,4012,4014,4016,4018],{"class":1034,"line":1374},[1032,4007,1220],{"class":1042},[1032,4009,3751],{"class":1049},[1032,4011,1226],{"class":1038},[1032,4013,1533],{"class":1042},[1032,4015,3751],{"class":1049},[1032,4017,3529],{"class":1038},[1032,4019,3913],{"class":1049},[1032,4021,4022],{"class":1034,"line":1396},[1032,4023,1306],{"class":1049},[1032,4025,4026],{"class":1034,"line":1401},[1032,4027,1312],{"class":1049},[1032,4029,4030],{"class":1034,"line":1406},[1032,4031,1087],{"emptyLinePlaceholder":1086},[1032,4033,4034,4036,4039],{"class":1034,"line":1411},[1032,4035,1192],{"class":1038},[1032,4037,4038],{"class":1195}," AddCommand",[1032,4040,1050],{"class":1049},[1032,4042,4043,4045,4047,4049],{"class":1034,"line":1421},[1032,4044,1204],{"class":1038},[1032,4046,1207],{"class":1049},[1032,4048,3893],{"class":1210},[1032,4050,1214],{"class":1049},[1032,4052,4053,4055,4058,4060],{"class":1034,"line":1433},[1032,4054,1220],{"class":1042},[1032,4056,4057],{"class":1049},".valueToAdd ",[1032,4059,1226],{"class":1038},[1032,4061,3913],{"class":1049},[1032,4063,4064],{"class":1034,"line":1442},[1032,4065,1306],{"class":1049},[1032,4067,4068],{"class":1034,"line":1458},[1032,4069,1087],{"emptyLinePlaceholder":1086},[1032,4071,4072,4075,4077,4080],{"class":1034,"line":1472},[1032,4073,4074],{"class":1195},"  execute",[1032,4076,1207],{"class":1049},[1032,4078,4079],{"class":1210},"currentValue",[1032,4081,1214],{"class":1049},[1032,4083,4084,4086,4089,4091,4093],{"class":1034,"line":1480},[1032,4085,1527],{"class":1038},[1032,4087,4088],{"class":1049}," currentValue ",[1032,4090,3910],{"class":1038},[1032,4092,1533],{"class":1042},[1032,4094,4095],{"class":1049},".valueToAdd;\n",[1032,4097,4098],{"class":1034,"line":1494},[1032,4099,1306],{"class":1049},[1032,4101,4102],{"class":1034,"line":1506},[1032,4103,1087],{"emptyLinePlaceholder":1086},[1032,4105,4106,4108,4110,4112],{"class":1034,"line":1513},[1032,4107,3836],{"class":1195},[1032,4109,1207],{"class":1049},[1032,4111,4079],{"class":1210},[1032,4113,1214],{"class":1049},[1032,4115,4116,4118,4120,4122,4124],{"class":1034,"line":1519},[1032,4117,1527],{"class":1038},[1032,4119,4088],{"class":1049},[1032,4121,3947],{"class":1038},[1032,4123,1533],{"class":1042},[1032,4125,4095],{"class":1049},[1032,4127,4128],{"class":1034,"line":1524},[1032,4129,1306],{"class":1049},[1032,4131,4132],{"class":1034,"line":1544},[1032,4133,1312],{"class":1049},[1032,4135,4136],{"class":1034,"line":1549},[1032,4137,1087],{"emptyLinePlaceholder":1086},[1032,4139,4140,4142,4145],{"class":1034,"line":1554},[1032,4141,1192],{"class":1038},[1032,4143,4144],{"class":1195}," SubtractCommand",[1032,4146,1050],{"class":1049},[1032,4148,4149,4151,4153,4155],{"class":1034,"line":1559},[1032,4150,1204],{"class":1038},[1032,4152,1207],{"class":1049},[1032,4154,3893],{"class":1210},[1032,4156,1214],{"class":1049},[1032,4158,4159,4161,4164,4166],{"class":1034,"line":1576},[1032,4160,1220],{"class":1042},[1032,4162,4163],{"class":1049},".valueToSubtract ",[1032,4165,1226],{"class":1038},[1032,4167,3913],{"class":1049},[1032,4169,4170],{"class":1034,"line":1581},[1032,4171,1306],{"class":1049},[1032,4173,4174],{"class":1034,"line":1600},[1032,4175,1087],{"emptyLinePlaceholder":1086},[1032,4177,4178,4180,4182,4184],{"class":1034,"line":1615},[1032,4179,4074],{"class":1195},[1032,4181,1207],{"class":1049},[1032,4183,4079],{"class":1210},[1032,4185,1214],{"class":1049},[1032,4187,4188,4190,4192,4194,4196],{"class":1034,"line":1631},[1032,4189,1527],{"class":1038},[1032,4191,4088],{"class":1049},[1032,4193,3947],{"class":1038},[1032,4195,1533],{"class":1042},[1032,4197,4198],{"class":1049},".valueToSubtract;\n",[1032,4200,4201],{"class":1034,"line":1642},[1032,4202,1306],{"class":1049},[1032,4204,4205],{"class":1034,"line":1648},[1032,4206,1087],{"emptyLinePlaceholder":1086},[1032,4208,4209,4211,4213,4215],{"class":1034,"line":1653},[1032,4210,3836],{"class":1195},[1032,4212,1207],{"class":1049},[1032,4214,4079],{"class":1210},[1032,4216,1214],{"class":1049},[1032,4218,4219,4221,4223,4225,4227],{"class":1034,"line":1669},[1032,4220,1527],{"class":1038},[1032,4222,4088],{"class":1049},[1032,4224,3910],{"class":1038},[1032,4226,1533],{"class":1042},[1032,4228,4198],{"class":1049},[1032,4230,4231],{"class":1034,"line":1682},[1032,4232,1306],{"class":1049},[1032,4234,4235],{"class":1034,"line":1695},[1032,4236,1312],{"class":1049},[1032,4238,4239],{"class":1034,"line":1705},[1032,4240,1087],{"emptyLinePlaceholder":1086},[1032,4242,4243,4245,4248],{"class":1034,"line":1710},[1032,4244,1192],{"class":1038},[1032,4246,4247],{"class":1195}," MultiplyCommand",[1032,4249,1050],{"class":1049},[1032,4251,4252,4254,4256,4258],{"class":1034,"line":1715},[1032,4253,1204],{"class":1038},[1032,4255,1207],{"class":1049},[1032,4257,3893],{"class":1210},[1032,4259,1214],{"class":1049},[1032,4261,4262,4264,4267,4269],{"class":1034,"line":1722},[1032,4263,1220],{"class":1042},[1032,4265,4266],{"class":1049},".valueToMultiply ",[1032,4268,1226],{"class":1038},[1032,4270,3913],{"class":1049},[1032,4272,4273],{"class":1034,"line":1746},[1032,4274,1306],{"class":1049},[1032,4276,4277],{"class":1034,"line":1752},[1032,4278,1087],{"emptyLinePlaceholder":1086},[1032,4280,4281,4283,4285,4287],{"class":1034,"line":1762},[1032,4282,4074],{"class":1195},[1032,4284,1207],{"class":1049},[1032,4286,4079],{"class":1210},[1032,4288,1214],{"class":1049},[1032,4290,4291,4293,4295,4297,4299],{"class":1034,"line":1767},[1032,4292,1527],{"class":1038},[1032,4294,4088],{"class":1049},[1032,4296,3547],{"class":1038},[1032,4298,1533],{"class":1042},[1032,4300,4301],{"class":1049},".valueToMultiply;\n",[1032,4303,4304],{"class":1034,"line":1787},[1032,4305,1306],{"class":1049},[1032,4307,4308],{"class":1034,"line":1793},[1032,4309,1087],{"emptyLinePlaceholder":1086},[1032,4311,4313,4315,4317,4319],{"class":1034,"line":4312},71,[1032,4314,3836],{"class":1195},[1032,4316,1207],{"class":1049},[1032,4318,4079],{"class":1210},[1032,4320,1214],{"class":1049},[1032,4322,4324,4326,4328,4330,4332],{"class":1034,"line":4323},72,[1032,4325,1527],{"class":1038},[1032,4327,4088],{"class":1049},[1032,4329,3529],{"class":1038},[1032,4331,1533],{"class":1042},[1032,4333,4301],{"class":1049},[1032,4335,4337],{"class":1034,"line":4336},73,[1032,4338,1306],{"class":1049},[1032,4340,4342],{"class":1034,"line":4341},74,[1032,4343,1312],{"class":1049},[1032,4345,4347],{"class":1034,"line":4346},75,[1032,4348,1087],{"emptyLinePlaceholder":1086},[1032,4350,4352,4354,4357],{"class":1034,"line":4351},76,[1032,4353,1192],{"class":1038},[1032,4355,4356],{"class":1195}," DivideCommand",[1032,4358,1050],{"class":1049},[1032,4360,4362,4364,4366,4368],{"class":1034,"line":4361},77,[1032,4363,1204],{"class":1038},[1032,4365,1207],{"class":1049},[1032,4367,3893],{"class":1210},[1032,4369,1214],{"class":1049},[1032,4371,4373,4375,4378,4380],{"class":1034,"line":4372},78,[1032,4374,1220],{"class":1042},[1032,4376,4377],{"class":1049},".valueToDivide ",[1032,4379,1226],{"class":1038},[1032,4381,3913],{"class":1049},[1032,4383,4385],{"class":1034,"line":4384},79,[1032,4386,1306],{"class":1049},[1032,4388,4390],{"class":1034,"line":4389},80,[1032,4391,1087],{"emptyLinePlaceholder":1086},[1032,4393,4395,4397,4399,4401],{"class":1034,"line":4394},81,[1032,4396,4074],{"class":1195},[1032,4398,1207],{"class":1049},[1032,4400,4079],{"class":1210},[1032,4402,1214],{"class":1049},[1032,4404,4406,4408,4410,4412,4414],{"class":1034,"line":4405},82,[1032,4407,1527],{"class":1038},[1032,4409,4088],{"class":1049},[1032,4411,3529],{"class":1038},[1032,4413,1533],{"class":1042},[1032,4415,4416],{"class":1049},".valueToDivide;\n",[1032,4418,4420],{"class":1034,"line":4419},83,[1032,4421,1306],{"class":1049},[1032,4423,4425],{"class":1034,"line":4424},84,[1032,4426,1087],{"emptyLinePlaceholder":1086},[1032,4428,4430,4432,4434,4436],{"class":1034,"line":4429},85,[1032,4431,3836],{"class":1195},[1032,4433,1207],{"class":1049},[1032,4435,4079],{"class":1210},[1032,4437,1214],{"class":1049},[1032,4439,4441,4443,4445,4447,4449],{"class":1034,"line":4440},86,[1032,4442,1527],{"class":1038},[1032,4444,4088],{"class":1049},[1032,4446,3547],{"class":1038},[1032,4448,1533],{"class":1042},[1032,4450,4416],{"class":1049},[1032,4452,4454],{"class":1034,"line":4453},87,[1032,4455,1306],{"class":1049},[1032,4457,4459],{"class":1034,"line":4458},88,[1032,4460,1312],{"class":1049},[1032,4462,4464],{"class":1034,"line":4463},89,[1032,4465,1087],{"emptyLinePlaceholder":1086},[1032,4467,4469,4471,4474,4476,4478,4480],{"class":1034,"line":4468},90,[1032,4470,1039],{"class":1038},[1032,4472,4473],{"class":1042}," calculator",[1032,4475,1046],{"class":1038},[1032,4477,1530],{"class":1038},[1032,4479,3736],{"class":1195},[1032,4481,1573],{"class":1049},[1032,4483,4485],{"class":1034,"line":4484},91,[1032,4486,1087],{"emptyLinePlaceholder":1086},[1032,4488,4490,4493,4496,4498,4501,4503,4505,4507],{"class":1034,"line":4489},92,[1032,4491,4492],{"class":1049},"calculator.",[1032,4494,4495],{"class":1195},"executeCommand",[1032,4497,1207],{"class":1049},[1032,4499,4500],{"class":1038},"new",[1032,4502,4038],{"class":1195},[1032,4504,1207],{"class":1049},[1032,4506,3663],{"class":1042},[1032,4508,4509],{"class":1049},"));\n",[1032,4511,4513,4515,4517,4519,4521,4523,4525,4528],{"class":1034,"line":4512},93,[1032,4514,4492],{"class":1049},[1032,4516,4495],{"class":1195},[1032,4518,1207],{"class":1049},[1032,4520,4500],{"class":1038},[1032,4522,4247],{"class":1195},[1032,4524,1207],{"class":1049},[1032,4526,4527],{"class":1042},"2",[1032,4529,4509],{"class":1049},[1032,4531,4533,4535,4537,4539,4541,4543,4545,4547],{"class":1034,"line":4532},94,[1032,4534,4492],{"class":1049},[1032,4536,4495],{"class":1195},[1032,4538,1207],{"class":1049},[1032,4540,4500],{"class":1038},[1032,4542,4144],{"class":1195},[1032,4544,1207],{"class":1049},[1032,4546,3663],{"class":1042},[1032,4548,4509],{"class":1049},[1032,4550,4552,4554,4556,4558,4560,4562,4564,4566],{"class":1034,"line":4551},95,[1032,4553,4492],{"class":1049},[1032,4555,4495],{"class":1195},[1032,4557,1207],{"class":1049},[1032,4559,4500],{"class":1038},[1032,4561,4356],{"class":1195},[1032,4563,1207],{"class":1049},[1032,4565,4527],{"class":1042},[1032,4567,4509],{"class":1049},[1032,4569,4571,4573,4575,4578],{"class":1034,"line":4570},96,[1032,4572,1725],{"class":1049},[1032,4574,1728],{"class":1195},[1032,4576,4577],{"class":1049},"(calculator.value); ",[1032,4579,4580],{"class":1718},"\u002F\u002F 5\n",[1032,4582,4584,4586,4588],{"class":1034,"line":4583},97,[1032,4585,4492],{"class":1049},[1032,4587,3869],{"class":1195},[1032,4589,1573],{"class":1049},[1032,4591,4593,4595,4597,4599],{"class":1034,"line":4592},98,[1032,4594,1725],{"class":1049},[1032,4596,1728],{"class":1195},[1032,4598,4577],{"class":1049},[1032,4600,4601],{"class":1718},"\u002F\u002F 10\n",[927,4603,4604],{},"JavaScript's function objects and callbacks are native command objects. They can be passed around like objects.",[953,4606,4608],{"id":4607},"interpreter","Interpreter",[927,4610,2138,4611,4615],{},[967,4612,4613],{},[930,4614,4608],{}," is a behavioral design pattern that offers a scripting language for end-users to customize their solution.",[927,4617,4618],{},[948,4619],{"alt":4608,"src":4620},"\u002Fimages\u002Fblog\u002F2021-12-16-javascript-design-patterns\u002Finterpreter.png",[927,4622,4623],{},"Some applications are so complex that they require advanced configuration. You could offer a basic scripting language that allows the end-user to manipulate your application through simple instructions. The Interpreter pattern solves this particular problem by introducing a simple scripting language.",[927,4625,4626],{},"The example below is to build an interpreter which translates roman numerals to decimal numbers.",[1022,4628,4630],{"className":1024,"code":4629,"language":1026,"meta":1027,"style":1027},"class Context {\n  constructor(input) {\n    this.input = input;\n    this.output = 0;\n  }\n\n  startsWith(str) {\n    return this.input.substr(0, str.length) === str;\n  }\n}\n\nclass Expression {\n  constructor(name, one, four, five, nine, multiplier) {\n    this.name = name;\n    this.one = one;\n    this.four = four;\n    this.five = five;\n    this.nine = nine;\n    this.multiplier = multiplier;\n  }\n\n  interpret(context) {\n    if (context.input.length == 0) {\n      return;\n    } else if (context.startsWith(this.nine)) {\n      context.output += 9 * this.multiplier;\n      context.input = context.input.substr(2);\n    } else if (context.startsWith(this.four)) {\n      context.output += 4 * this.multiplier;\n      context.input = context.input.substr(2);\n    } else if (context.startsWith(this.five)) {\n      context.output += 5 * this.multiplier;\n      context.input = context.input.substr(1);\n    }\n\n    while (context.startsWith(this.one)) {\n      context.output += 1 * this.multiplier;\n      context.input = context.input.substr(1);\n    }\n  }\n}\n\nconst roman = 'MCMLXXVII';\nconst context = new Context(roman);\nconst tree = [];\n\ntree.push(new Expression('thousand', 'M', ' ', ' ', ' ', 1000));\ntree.push(new Expression('hundred', 'C', 'CD', 'D', 'CM', 100));\ntree.push(new Expression('ten', 'X', 'XL', 'L', 'XC', 10));\ntree.push(new Expression('one', 'I', 'IV', 'V', 'IX', 1));\n\nfor (let i = 0, len = tree.length; i \u003C len; i++) {\n  tree[i].interpret(context);\n}\n\nconsole.log(roman + ' = ' + context.output); \u002F\u002F 1977\n",[1029,4631,4632,4641,4652,4664,4677,4681,4685,4697,4728,4732,4736,4740,4749,4785,4797,4809,4821,4833,4845,4857,4861,4865,4877,4893,4899,4923,4942,4960,4979,4993,5009,5028,5043,5060,5064,5068,5084,5099,5115,5119,5123,5127,5131,5145,5161,5172,5176,5219,5262,5305,5348,5352,5394,5405,5409,5413],{"__ignoreMap":1027},[1032,4633,4634,4636,4639],{"class":1034,"line":1035},[1032,4635,1192],{"class":1038},[1032,4637,4638],{"class":1195}," Context",[1032,4640,1050],{"class":1049},[1032,4642,4643,4645,4647,4650],{"class":1034,"line":1053},[1032,4644,1204],{"class":1038},[1032,4646,1207],{"class":1049},[1032,4648,4649],{"class":1210},"input",[1032,4651,1214],{"class":1049},[1032,4653,4654,4656,4659,4661],{"class":1034,"line":1066},[1032,4655,1220],{"class":1042},[1032,4657,4658],{"class":1049},".input ",[1032,4660,1226],{"class":1038},[1032,4662,4663],{"class":1049}," input;\n",[1032,4665,4666,4668,4671,4673,4675],{"class":1034,"line":1077},[1032,4667,1220],{"class":1042},[1032,4669,4670],{"class":1049},".output ",[1032,4672,1226],{"class":1038},[1032,4674,3756],{"class":1042},[1032,4676,1251],{"class":1049},[1032,4678,4679],{"class":1034,"line":1083},[1032,4680,1306],{"class":1049},[1032,4682,4683],{"class":1034,"line":1090},[1032,4684,1087],{"emptyLinePlaceholder":1086},[1032,4686,4687,4690,4692,4695],{"class":1034,"line":1102},[1032,4688,4689],{"class":1195},"  startsWith",[1032,4691,1207],{"class":1049},[1032,4693,4694],{"class":1210},"str",[1032,4696,1214],{"class":1049},[1032,4698,4699,4701,4703,4706,4709,4711,4714,4717,4720,4723,4725],{"class":1034,"line":1113},[1032,4700,1527],{"class":1038},[1032,4702,1533],{"class":1042},[1032,4704,4705],{"class":1049},".input.",[1032,4707,4708],{"class":1195},"substr",[1032,4710,1207],{"class":1049},[1032,4712,4713],{"class":1042},"0",[1032,4715,4716],{"class":1049},", str.",[1032,4718,4719],{"class":1042},"length",[1032,4721,4722],{"class":1049},") ",[1032,4724,1734],{"class":1038},[1032,4726,4727],{"class":1049}," str;\n",[1032,4729,4730],{"class":1034,"line":1124},[1032,4731,1306],{"class":1049},[1032,4733,4734],{"class":1034,"line":1135},[1032,4735,1312],{"class":1049},[1032,4737,4738],{"class":1034,"line":1140},[1032,4739,1087],{"emptyLinePlaceholder":1086},[1032,4741,4742,4744,4747],{"class":1034,"line":1145},[1032,4743,1192],{"class":1038},[1032,4745,4746],{"class":1195}," Expression",[1032,4748,1050],{"class":1049},[1032,4750,4751,4753,4755,4758,4760,4763,4765,4768,4770,4773,4775,4778,4780,4783],{"class":1034,"line":1157},[1032,4752,1204],{"class":1038},[1032,4754,1207],{"class":1049},[1032,4756,4757],{"class":1210},"name",[1032,4759,2819],{"class":1049},[1032,4761,4762],{"class":1210},"one",[1032,4764,2819],{"class":1049},[1032,4766,4767],{"class":1210},"four",[1032,4769,2819],{"class":1049},[1032,4771,4772],{"class":1210},"five",[1032,4774,2819],{"class":1049},[1032,4776,4777],{"class":1210},"nine",[1032,4779,2819],{"class":1049},[1032,4781,4782],{"class":1210},"multiplier",[1032,4784,1214],{"class":1049},[1032,4786,4787,4789,4792,4794],{"class":1034,"line":1168},[1032,4788,1220],{"class":1042},[1032,4790,4791],{"class":1049},".name ",[1032,4793,1226],{"class":1038},[1032,4795,4796],{"class":1049}," name;\n",[1032,4798,4799,4801,4804,4806],{"class":1034,"line":1179},[1032,4800,1220],{"class":1042},[1032,4802,4803],{"class":1049},".one ",[1032,4805,1226],{"class":1038},[1032,4807,4808],{"class":1049}," one;\n",[1032,4810,4811,4813,4816,4818],{"class":1034,"line":1184},[1032,4812,1220],{"class":1042},[1032,4814,4815],{"class":1049},".four ",[1032,4817,1226],{"class":1038},[1032,4819,4820],{"class":1049}," four;\n",[1032,4822,4823,4825,4828,4830],{"class":1034,"line":1189},[1032,4824,1220],{"class":1042},[1032,4826,4827],{"class":1049},".five ",[1032,4829,1226],{"class":1038},[1032,4831,4832],{"class":1049}," five;\n",[1032,4834,4835,4837,4840,4842],{"class":1034,"line":1201},[1032,4836,1220],{"class":1042},[1032,4838,4839],{"class":1049},".nine ",[1032,4841,1226],{"class":1038},[1032,4843,4844],{"class":1049}," nine;\n",[1032,4846,4847,4849,4852,4854],{"class":1034,"line":1217},[1032,4848,1220],{"class":1042},[1032,4850,4851],{"class":1049},".multiplier ",[1032,4853,1226],{"class":1038},[1032,4855,4856],{"class":1049}," multiplier;\n",[1032,4858,4859],{"class":1034,"line":1232},[1032,4860,1306],{"class":1049},[1032,4862,4863],{"class":1034,"line":1254},[1032,4864,1087],{"emptyLinePlaceholder":1086},[1032,4866,4867,4870,4872,4875],{"class":1034,"line":1279},[1032,4868,4869],{"class":1195},"  interpret",[1032,4871,1207],{"class":1049},[1032,4873,4874],{"class":1210},"context",[1032,4876,1214],{"class":1049},[1032,4878,4879,4881,4884,4886,4889,4891],{"class":1034,"line":1303},[1032,4880,3212],{"class":1038},[1032,4882,4883],{"class":1049}," (context.input.",[1032,4885,4719],{"class":1042},[1032,4887,4888],{"class":1038}," ==",[1032,4890,3756],{"class":1042},[1032,4892,1214],{"class":1049},[1032,4894,4895,4897],{"class":1034,"line":1309},[1032,4896,3220],{"class":1038},[1032,4898,1251],{"class":1049},[1032,4900,4901,4904,4907,4910,4913,4916,4918,4920],{"class":1034,"line":1315},[1032,4902,4903],{"class":1049},"    } ",[1032,4905,4906],{"class":1038},"else",[1032,4908,4909],{"class":1038}," if",[1032,4911,4912],{"class":1049}," (context.",[1032,4914,4915],{"class":1195},"startsWith",[1032,4917,1207],{"class":1049},[1032,4919,2298],{"class":1042},[1032,4921,4922],{"class":1049},".nine)) {\n",[1032,4924,4925,4928,4931,4934,4937,4939],{"class":1034,"line":1320},[1032,4926,4927],{"class":1049},"      context.output ",[1032,4929,4930],{"class":1038},"+=",[1032,4932,4933],{"class":1042}," 9",[1032,4935,4936],{"class":1038}," *",[1032,4938,1533],{"class":1042},[1032,4940,4941],{"class":1049},".multiplier;\n",[1032,4943,4944,4947,4949,4952,4954,4956,4958],{"class":1034,"line":1330},[1032,4945,4946],{"class":1049},"      context.input ",[1032,4948,1226],{"class":1038},[1032,4950,4951],{"class":1049}," context.input.",[1032,4953,4708],{"class":1195},[1032,4955,1207],{"class":1049},[1032,4957,4527],{"class":1042},[1032,4959,1743],{"class":1049},[1032,4961,4962,4964,4966,4968,4970,4972,4974,4976],{"class":1034,"line":1341},[1032,4963,4903],{"class":1049},[1032,4965,4906],{"class":1038},[1032,4967,4909],{"class":1038},[1032,4969,4912],{"class":1049},[1032,4971,4915],{"class":1195},[1032,4973,1207],{"class":1049},[1032,4975,2298],{"class":1042},[1032,4977,4978],{"class":1049},".four)) {\n",[1032,4980,4981,4983,4985,4987,4989,4991],{"class":1034,"line":1352},[1032,4982,4927],{"class":1049},[1032,4984,4930],{"class":1038},[1032,4986,1248],{"class":1042},[1032,4988,4936],{"class":1038},[1032,4990,1533],{"class":1042},[1032,4992,4941],{"class":1049},[1032,4994,4995,4997,4999,5001,5003,5005,5007],{"class":1034,"line":1374},[1032,4996,4946],{"class":1049},[1032,4998,1226],{"class":1038},[1032,5000,4951],{"class":1049},[1032,5002,4708],{"class":1195},[1032,5004,1207],{"class":1049},[1032,5006,4527],{"class":1042},[1032,5008,1743],{"class":1049},[1032,5010,5011,5013,5015,5017,5019,5021,5023,5025],{"class":1034,"line":1396},[1032,5012,4903],{"class":1049},[1032,5014,4906],{"class":1038},[1032,5016,4909],{"class":1038},[1032,5018,4912],{"class":1049},[1032,5020,4915],{"class":1195},[1032,5022,1207],{"class":1049},[1032,5024,2298],{"class":1042},[1032,5026,5027],{"class":1049},".five)) {\n",[1032,5029,5030,5032,5034,5037,5039,5041],{"class":1034,"line":1401},[1032,5031,4927],{"class":1049},[1032,5033,4930],{"class":1038},[1032,5035,5036],{"class":1042}," 5",[1032,5038,4936],{"class":1038},[1032,5040,1533],{"class":1042},[1032,5042,4941],{"class":1049},[1032,5044,5045,5047,5049,5051,5053,5055,5058],{"class":1034,"line":1406},[1032,5046,4946],{"class":1049},[1032,5048,1226],{"class":1038},[1032,5050,4951],{"class":1049},[1032,5052,4708],{"class":1195},[1032,5054,1207],{"class":1049},[1032,5056,5057],{"class":1042},"1",[1032,5059,1743],{"class":1049},[1032,5061,5062],{"class":1034,"line":1411},[1032,5063,1516],{"class":1049},[1032,5065,5066],{"class":1034,"line":1421},[1032,5067,1087],{"emptyLinePlaceholder":1086},[1032,5069,5070,5073,5075,5077,5079,5081],{"class":1034,"line":1433},[1032,5071,5072],{"class":1038},"    while",[1032,5074,4912],{"class":1049},[1032,5076,4915],{"class":1195},[1032,5078,1207],{"class":1049},[1032,5080,2298],{"class":1042},[1032,5082,5083],{"class":1049},".one)) {\n",[1032,5085,5086,5088,5090,5093,5095,5097],{"class":1034,"line":1442},[1032,5087,4927],{"class":1049},[1032,5089,4930],{"class":1038},[1032,5091,5092],{"class":1042}," 1",[1032,5094,4936],{"class":1038},[1032,5096,1533],{"class":1042},[1032,5098,4941],{"class":1049},[1032,5100,5101,5103,5105,5107,5109,5111,5113],{"class":1034,"line":1458},[1032,5102,4946],{"class":1049},[1032,5104,1226],{"class":1038},[1032,5106,4951],{"class":1049},[1032,5108,4708],{"class":1195},[1032,5110,1207],{"class":1049},[1032,5112,5057],{"class":1042},[1032,5114,1743],{"class":1049},[1032,5116,5117],{"class":1034,"line":1472},[1032,5118,1516],{"class":1049},[1032,5120,5121],{"class":1034,"line":1480},[1032,5122,1306],{"class":1049},[1032,5124,5125],{"class":1034,"line":1494},[1032,5126,1312],{"class":1049},[1032,5128,5129],{"class":1034,"line":1506},[1032,5130,1087],{"emptyLinePlaceholder":1086},[1032,5132,5133,5135,5138,5140,5143],{"class":1034,"line":1513},[1032,5134,1039],{"class":1038},[1032,5136,5137],{"class":1042}," roman",[1032,5139,1046],{"class":1038},[1032,5141,5142],{"class":1059}," 'MCMLXXVII'",[1032,5144,1251],{"class":1049},[1032,5146,5147,5149,5152,5154,5156,5158],{"class":1034,"line":1519},[1032,5148,1039],{"class":1038},[1032,5150,5151],{"class":1042}," context",[1032,5153,1046],{"class":1038},[1032,5155,1530],{"class":1038},[1032,5157,4638],{"class":1195},[1032,5159,5160],{"class":1049},"(roman);\n",[1032,5162,5163,5165,5168,5170],{"class":1034,"line":1524},[1032,5164,1039],{"class":1038},[1032,5166,5167],{"class":1042}," tree",[1032,5169,1046],{"class":1038},[1032,5171,3770],{"class":1049},[1032,5173,5174],{"class":1034,"line":1544},[1032,5175,1087],{"emptyLinePlaceholder":1086},[1032,5177,5178,5181,5183,5185,5187,5189,5191,5194,5196,5199,5201,5204,5206,5208,5210,5212,5214,5217],{"class":1034,"line":1549},[1032,5179,5180],{"class":1049},"tree.",[1032,5182,3820],{"class":1195},[1032,5184,1207],{"class":1049},[1032,5186,4500],{"class":1038},[1032,5188,4746],{"class":1195},[1032,5190,1207],{"class":1049},[1032,5192,5193],{"class":1059},"'thousand'",[1032,5195,2819],{"class":1049},[1032,5197,5198],{"class":1059},"'M'",[1032,5200,2819],{"class":1049},[1032,5202,5203],{"class":1059},"' '",[1032,5205,2819],{"class":1049},[1032,5207,5203],{"class":1059},[1032,5209,2819],{"class":1049},[1032,5211,5203],{"class":1059},[1032,5213,2819],{"class":1049},[1032,5215,5216],{"class":1042},"1000",[1032,5218,4509],{"class":1049},[1032,5220,5221,5223,5225,5227,5229,5231,5233,5236,5238,5241,5243,5246,5248,5251,5253,5256,5258,5260],{"class":1034,"line":1554},[1032,5222,5180],{"class":1049},[1032,5224,3820],{"class":1195},[1032,5226,1207],{"class":1049},[1032,5228,4500],{"class":1038},[1032,5230,4746],{"class":1195},[1032,5232,1207],{"class":1049},[1032,5234,5235],{"class":1059},"'hundred'",[1032,5237,2819],{"class":1049},[1032,5239,5240],{"class":1059},"'C'",[1032,5242,2819],{"class":1049},[1032,5244,5245],{"class":1059},"'CD'",[1032,5247,2819],{"class":1049},[1032,5249,5250],{"class":1059},"'D'",[1032,5252,2819],{"class":1049},[1032,5254,5255],{"class":1059},"'CM'",[1032,5257,2819],{"class":1049},[1032,5259,3635],{"class":1042},[1032,5261,4509],{"class":1049},[1032,5263,5264,5266,5268,5270,5272,5274,5276,5279,5281,5284,5286,5289,5291,5294,5296,5299,5301,5303],{"class":1034,"line":1559},[1032,5265,5180],{"class":1049},[1032,5267,3820],{"class":1195},[1032,5269,1207],{"class":1049},[1032,5271,4500],{"class":1038},[1032,5273,4746],{"class":1195},[1032,5275,1207],{"class":1049},[1032,5277,5278],{"class":1059},"'ten'",[1032,5280,2819],{"class":1049},[1032,5282,5283],{"class":1059},"'X'",[1032,5285,2819],{"class":1049},[1032,5287,5288],{"class":1059},"'XL'",[1032,5290,2819],{"class":1049},[1032,5292,5293],{"class":1059},"'L'",[1032,5295,2819],{"class":1049},[1032,5297,5298],{"class":1059},"'XC'",[1032,5300,2819],{"class":1049},[1032,5302,3663],{"class":1042},[1032,5304,4509],{"class":1049},[1032,5306,5307,5309,5311,5313,5315,5317,5319,5322,5324,5327,5329,5332,5334,5337,5339,5342,5344,5346],{"class":1034,"line":1576},[1032,5308,5180],{"class":1049},[1032,5310,3820],{"class":1195},[1032,5312,1207],{"class":1049},[1032,5314,4500],{"class":1038},[1032,5316,4746],{"class":1195},[1032,5318,1207],{"class":1049},[1032,5320,5321],{"class":1059},"'one'",[1032,5323,2819],{"class":1049},[1032,5325,5326],{"class":1059},"'I'",[1032,5328,2819],{"class":1049},[1032,5330,5331],{"class":1059},"'IV'",[1032,5333,2819],{"class":1049},[1032,5335,5336],{"class":1059},"'V'",[1032,5338,2819],{"class":1049},[1032,5340,5341],{"class":1059},"'IX'",[1032,5343,2819],{"class":1049},[1032,5345,5057],{"class":1042},[1032,5347,4509],{"class":1049},[1032,5349,5350],{"class":1034,"line":1581},[1032,5351,1087],{"emptyLinePlaceholder":1086},[1032,5353,5354,5357,5360,5363,5366,5368,5370,5373,5375,5378,5380,5383,5386,5389,5392],{"class":1034,"line":1600},[1032,5355,5356],{"class":1038},"for",[1032,5358,5359],{"class":1049}," (",[1032,5361,5362],{"class":1038},"let",[1032,5364,5365],{"class":1049}," i ",[1032,5367,1226],{"class":1038},[1032,5369,3756],{"class":1042},[1032,5371,5372],{"class":1049},", len ",[1032,5374,1226],{"class":1038},[1032,5376,5377],{"class":1049}," tree.",[1032,5379,4719],{"class":1042},[1032,5381,5382],{"class":1049},"; i ",[1032,5384,5385],{"class":1038},"\u003C",[1032,5387,5388],{"class":1049}," len; i",[1032,5390,5391],{"class":1038},"++",[1032,5393,1214],{"class":1049},[1032,5395,5396,5399,5402],{"class":1034,"line":1615},[1032,5397,5398],{"class":1049},"  tree[i].",[1032,5400,5401],{"class":1195},"interpret",[1032,5403,5404],{"class":1049},"(context);\n",[1032,5406,5407],{"class":1034,"line":1631},[1032,5408,1312],{"class":1049},[1032,5410,5411],{"class":1034,"line":1642},[1032,5412,1087],{"emptyLinePlaceholder":1086},[1032,5414,5415,5417,5419,5422,5424,5427,5430,5433],{"class":1034,"line":1648},[1032,5416,1725],{"class":1049},[1032,5418,1728],{"class":1195},[1032,5420,5421],{"class":1049},"(roman ",[1032,5423,3910],{"class":1038},[1032,5425,5426],{"class":1059}," ' = '",[1032,5428,5429],{"class":1038}," +",[1032,5431,5432],{"class":1049}," context.output); ",[1032,5434,5435],{"class":1718},"\u002F\u002F 1977\n",[927,5437,5438],{},"The Context object - maintains the input which is the roman numeral and the resulting output as it is being parsed and interpreted. The Expression object - represents the nodes in the grammar tree and it supports the interpret method.",[953,5440,5442],{"id":5441},"iterator","Iterator",[927,5444,5445,5449],{},[967,5446,5447],{},[930,5448,5442],{}," is a behavioral design pattern that accesses the elements of an object without exposing its underlying representation.",[927,5451,5452],{},"It is a common task in programming to traverse and manipulate a collection of objects. These collections may be stored as an array or perhaps something more complex, such as a tree or graph structure. In addition, you may need to access the items in the collection in a certain order, such as, front to back, back to front, depth-first (as in tree searches), skip evenly numbered objects, etc.",[927,5454,5455],{},[948,5456],{"alt":5442,"src":5457},"\u002Fimages\u002Fblog\u002F2021-12-16-javascript-design-patterns\u002Fiterator.png",[927,5459,2138,5460,5462,5463,5466,5467,5466,5470,5466,5473,5476,5477,1271],{},[1029,5461,5442],{}," object maintains a reference to the collection and the current position. It also implements the 'standard' Iterator interface with methods like: ",[1029,5464,5465],{},"first",", ",[1029,5468,5469],{},"next",[1029,5471,5472],{},"hasNext",[1029,5474,5475],{},"reset",", and ",[1029,5478,5479],{},"each",[1022,5481,5483],{"className":1024,"code":5482,"language":1026,"meta":1027,"style":1027},"class Iterator {\n  constructor(items) {\n    this.index = 0;\n    this.items = items;\n  }\n\n  first() {\n    this.reset();\n    return this.next();\n  }\n\n  next() {\n    return this.items[this.index++];\n  }\n\n  hasNext() {\n    return this.index \u003C= this.items.length;\n  }\n\n  reset() {\n    this.index = 0;\n  }\n\n  each(callback) {\n    for (let item = this.first(); this.hasNext(); item = this.next()) {\n      callback(item);\n    }\n  }\n}\n\nconst items = ['Apple', 'Banana', 'Pear', 'Orange'];\nconst iter = new Iterator(items);\n\niter.each(function (item) {\n  console.log(item);\n});\n",[1029,5484,5485,5494,5505,5518,5530,5534,5538,5545,5555,5567,5571,5575,5582,5601,5605,5609,5616,5636,5640,5644,5651,5663,5667,5671,5683,5725,5733,5737,5741,5745,5749,5781,5797,5801,5820,5829],{"__ignoreMap":1027},[1032,5486,5487,5489,5492],{"class":1034,"line":1035},[1032,5488,1192],{"class":1038},[1032,5490,5491],{"class":1195}," Iterator",[1032,5493,1050],{"class":1049},[1032,5495,5496,5498,5500,5503],{"class":1034,"line":1053},[1032,5497,1204],{"class":1038},[1032,5499,1207],{"class":1049},[1032,5501,5502],{"class":1210},"items",[1032,5504,1214],{"class":1049},[1032,5506,5507,5509,5512,5514,5516],{"class":1034,"line":1066},[1032,5508,1220],{"class":1042},[1032,5510,5511],{"class":1049},".index ",[1032,5513,1226],{"class":1038},[1032,5515,3756],{"class":1042},[1032,5517,1251],{"class":1049},[1032,5519,5520,5522,5525,5527],{"class":1034,"line":1077},[1032,5521,1220],{"class":1042},[1032,5523,5524],{"class":1049},".items ",[1032,5526,1226],{"class":1038},[1032,5528,5529],{"class":1049}," items;\n",[1032,5531,5532],{"class":1034,"line":1083},[1032,5533,1306],{"class":1049},[1032,5535,5536],{"class":1034,"line":1090},[1032,5537,1087],{"emptyLinePlaceholder":1086},[1032,5539,5540,5543],{"class":1034,"line":1102},[1032,5541,5542],{"class":1195},"  first",[1032,5544,1868],{"class":1049},[1032,5546,5547,5549,5551,5553],{"class":1034,"line":1113},[1032,5548,1220],{"class":1042},[1032,5550,1271],{"class":1049},[1032,5552,5475],{"class":1195},[1032,5554,1573],{"class":1049},[1032,5556,5557,5559,5561,5563,5565],{"class":1034,"line":1124},[1032,5558,1527],{"class":1038},[1032,5560,1533],{"class":1042},[1032,5562,1271],{"class":1049},[1032,5564,5469],{"class":1195},[1032,5566,1573],{"class":1049},[1032,5568,5569],{"class":1034,"line":1135},[1032,5570,1306],{"class":1049},[1032,5572,5573],{"class":1034,"line":1140},[1032,5574,1087],{"emptyLinePlaceholder":1086},[1032,5576,5577,5580],{"class":1034,"line":1145},[1032,5578,5579],{"class":1195},"  next",[1032,5581,1868],{"class":1049},[1032,5583,5584,5586,5588,5591,5593,5596,5598],{"class":1034,"line":1157},[1032,5585,1527],{"class":1038},[1032,5587,1533],{"class":1042},[1032,5589,5590],{"class":1049},".items[",[1032,5592,2298],{"class":1042},[1032,5594,5595],{"class":1049},".index",[1032,5597,5391],{"class":1038},[1032,5599,5600],{"class":1049},"];\n",[1032,5602,5603],{"class":1034,"line":1168},[1032,5604,1306],{"class":1049},[1032,5606,5607],{"class":1034,"line":1179},[1032,5608,1087],{"emptyLinePlaceholder":1086},[1032,5610,5611,5614],{"class":1034,"line":1184},[1032,5612,5613],{"class":1195},"  hasNext",[1032,5615,1868],{"class":1049},[1032,5617,5618,5620,5622,5624,5627,5629,5632,5634],{"class":1034,"line":1189},[1032,5619,1527],{"class":1038},[1032,5621,1533],{"class":1042},[1032,5623,5511],{"class":1049},[1032,5625,5626],{"class":1038},"\u003C=",[1032,5628,1533],{"class":1042},[1032,5630,5631],{"class":1049},".items.",[1032,5633,4719],{"class":1042},[1032,5635,1251],{"class":1049},[1032,5637,5638],{"class":1034,"line":1201},[1032,5639,1306],{"class":1049},[1032,5641,5642],{"class":1034,"line":1217},[1032,5643,1087],{"emptyLinePlaceholder":1086},[1032,5645,5646,5649],{"class":1034,"line":1232},[1032,5647,5648],{"class":1195},"  reset",[1032,5650,1868],{"class":1049},[1032,5652,5653,5655,5657,5659,5661],{"class":1034,"line":1254},[1032,5654,1220],{"class":1042},[1032,5656,5511],{"class":1049},[1032,5658,1226],{"class":1038},[1032,5660,3756],{"class":1042},[1032,5662,1251],{"class":1049},[1032,5664,5665],{"class":1034,"line":1279},[1032,5666,1306],{"class":1049},[1032,5668,5669],{"class":1034,"line":1303},[1032,5670,1087],{"emptyLinePlaceholder":1086},[1032,5672,5673,5676,5678,5681],{"class":1034,"line":1309},[1032,5674,5675],{"class":1195},"  each",[1032,5677,1207],{"class":1049},[1032,5679,5680],{"class":1210},"callback",[1032,5682,1214],{"class":1049},[1032,5684,5685,5688,5690,5692,5695,5697,5699,5701,5703,5706,5708,5710,5712,5715,5717,5719,5721,5723],{"class":1034,"line":1315},[1032,5686,5687],{"class":1038},"    for",[1032,5689,5359],{"class":1049},[1032,5691,5362],{"class":1038},[1032,5693,5694],{"class":1049}," item ",[1032,5696,1226],{"class":1038},[1032,5698,1533],{"class":1042},[1032,5700,1271],{"class":1049},[1032,5702,5465],{"class":1195},[1032,5704,5705],{"class":1049},"(); ",[1032,5707,2298],{"class":1042},[1032,5709,1271],{"class":1049},[1032,5711,5472],{"class":1195},[1032,5713,5714],{"class":1049},"(); item ",[1032,5716,1226],{"class":1038},[1032,5718,1533],{"class":1042},[1032,5720,1271],{"class":1049},[1032,5722,5469],{"class":1195},[1032,5724,2390],{"class":1049},[1032,5726,5727,5730],{"class":1034,"line":1320},[1032,5728,5729],{"class":1195},"      callback",[1032,5731,5732],{"class":1049},"(item);\n",[1032,5734,5735],{"class":1034,"line":1330},[1032,5736,1516],{"class":1049},[1032,5738,5739],{"class":1034,"line":1341},[1032,5740,1306],{"class":1049},[1032,5742,5743],{"class":1034,"line":1352},[1032,5744,1312],{"class":1049},[1032,5746,5747],{"class":1034,"line":1374},[1032,5748,1087],{"emptyLinePlaceholder":1086},[1032,5750,5751,5753,5756,5758,5761,5764,5766,5769,5771,5774,5776,5779],{"class":1034,"line":1396},[1032,5752,1039],{"class":1038},[1032,5754,5755],{"class":1042}," items",[1032,5757,1046],{"class":1038},[1032,5759,5760],{"class":1049}," [",[1032,5762,5763],{"class":1059},"'Apple'",[1032,5765,2819],{"class":1049},[1032,5767,5768],{"class":1059},"'Banana'",[1032,5770,2819],{"class":1049},[1032,5772,5773],{"class":1059},"'Pear'",[1032,5775,2819],{"class":1049},[1032,5777,5778],{"class":1059},"'Orange'",[1032,5780,5600],{"class":1049},[1032,5782,5783,5785,5788,5790,5792,5794],{"class":1034,"line":1401},[1032,5784,1039],{"class":1038},[1032,5786,5787],{"class":1042}," iter",[1032,5789,1046],{"class":1038},[1032,5791,1530],{"class":1038},[1032,5793,5491],{"class":1195},[1032,5795,5796],{"class":1049},"(items);\n",[1032,5798,5799],{"class":1034,"line":1406},[1032,5800,1087],{"emptyLinePlaceholder":1086},[1032,5802,5803,5806,5808,5810,5813,5815,5818],{"class":1034,"line":1411},[1032,5804,5805],{"class":1049},"iter.",[1032,5807,5479],{"class":1195},[1032,5809,1207],{"class":1049},[1032,5811,5812],{"class":1038},"function",[1032,5814,5359],{"class":1049},[1032,5816,5817],{"class":1210},"item",[1032,5819,1214],{"class":1049},[1032,5821,5822,5825,5827],{"class":1034,"line":1421},[1032,5823,5824],{"class":1049},"  console.",[1032,5826,1728],{"class":1195},[1032,5828,5732],{"class":1049},[1032,5830,5831],{"class":1034,"line":1433},[1032,5832,1645],{"class":1049},[927,5834,2138,5835,5837,5838,5840,5841,5466,5843,5476,5845,5847],{},[1029,5836,5479],{}," method internally uses the ",[1029,5839,5356],{}," loop which uses the ",[1029,5842,5465],{},[1029,5844,5472],{},[1029,5846,5469],{}," methods to control the iteration. But to the client, the syntax has been greatly simplified.",[953,5849,5851],{"id":5850},"mediator","Mediator",[927,5853,2741,5854,5858],{},[967,5855,5856],{},[930,5857,5851],{}," is a behavioral design pattern that adds a third-party object to control the interaction between two objects. It allows loose coupling between classes by being the only class that has detailed knowledge of their methods.",[927,5860,5861],{},[948,5862],{"alt":5851,"src":5863},"\u002Fimages\u002Fblog\u002F2021-12-16-javascript-design-patterns\u002Fmediator.png",[927,5865,2138,5866,5870],{},[967,5867,5868],{},[930,5869,5851],{}," pattern provides central authority over a group of objects by encapsulating how these objects interact. This model is useful for scenarios where there is a need to manage complex conditions in which every object is aware of any state change in any other object in the group.",[927,5872,5873,5874,5877,5878,5881],{},"Let’s look at an example where we have four participants that are joining in a chat session by registering with a ",[1029,5875,5876],{},"Chatroom"," (the Mediator). Each participant is represented by a ",[1029,5879,5880],{},"Participant"," object. Participants send messages to each other and the Chatroom manages the routing.",[1022,5883,5885],{"className":1024,"code":5884,"language":1026,"meta":1027,"style":1027},"class Participant {\n  constructor(name) {\n    this.name = name;\n    this.chatroom = null;\n  }\n\n  send(message, to) {\n    this.chatroom.send(message, this, to);\n  }\n\n  receive(message, from) {\n    console.log(from.name + ' -> ' + this.name + ': ' + message);\n  }\n}\n\nclass Chatroom {\n  constructor() {\n    this.participants = {};\n  }\n\n  join(participant) {\n    this.participants[participant.name] = participant;\n    participant.chatroom = this;\n  }\n\n  send(message, from, to) {\n    if (to) {\n      \u002F\u002F single message\n      to.receive(message, from);\n    } else {\n      \u002F\u002F broadcast message\n      for (const key in this.participants) {\n        if (this.participants[key] !== from) {\n          this.participants[key].receive(message, from);\n        }\n      }\n    }\n  }\n}\n\nconst michael = new Participant('Michael');\nconst jane = new Participant('Jane');\nconst paul = new Participant('Paul');\nconst emily = new Participant('Emily');\n\nconst chatroom = new Chatroom();\nchatroom.join(michael);\nchatroom.join(jane);\nchatroom.join(paul);\nchatroom.join(emily);\n\nmichael.send('Hey Jane, how was your weekend?');\njane.send('Hey Michael, it was great. How was yours?', michael);\npaul.send('Hey peeps, how are we going?');\nemily.send('Great Paul. Thank you', paul);\n",[1029,5886,5887,5896,5906,5916,5930,5934,5938,5955,5973,5977,5981,5997,6027,6031,6035,6039,6048,6054,6066,6070,6074,6086,6098,6109,6113,6117,6135,6142,6147,6158,6166,6171,6191,6209,6221,6226,6231,6235,6239,6243,6247,6267,6287,6307,6327,6331,6346,6357,6366,6375,6384,6388,6402,6417,6431],{"__ignoreMap":1027},[1032,5888,5889,5891,5894],{"class":1034,"line":1035},[1032,5890,1192],{"class":1038},[1032,5892,5893],{"class":1195}," Participant",[1032,5895,1050],{"class":1049},[1032,5897,5898,5900,5902,5904],{"class":1034,"line":1053},[1032,5899,1204],{"class":1038},[1032,5901,1207],{"class":1049},[1032,5903,4757],{"class":1210},[1032,5905,1214],{"class":1049},[1032,5907,5908,5910,5912,5914],{"class":1034,"line":1066},[1032,5909,1220],{"class":1042},[1032,5911,4791],{"class":1049},[1032,5913,1226],{"class":1038},[1032,5915,4796],{"class":1049},[1032,5917,5918,5920,5923,5925,5928],{"class":1034,"line":1077},[1032,5919,1220],{"class":1042},[1032,5921,5922],{"class":1049},".chatroom ",[1032,5924,1226],{"class":1038},[1032,5926,5927],{"class":1042}," null",[1032,5929,1251],{"class":1049},[1032,5931,5932],{"class":1034,"line":1083},[1032,5933,1306],{"class":1049},[1032,5935,5936],{"class":1034,"line":1090},[1032,5937,1087],{"emptyLinePlaceholder":1086},[1032,5939,5940,5943,5945,5948,5950,5953],{"class":1034,"line":1102},[1032,5941,5942],{"class":1195},"  send",[1032,5944,1207],{"class":1049},[1032,5946,5947],{"class":1210},"message",[1032,5949,2819],{"class":1049},[1032,5951,5952],{"class":1210},"to",[1032,5954,1214],{"class":1049},[1032,5956,5957,5959,5962,5965,5968,5970],{"class":1034,"line":1113},[1032,5958,1220],{"class":1042},[1032,5960,5961],{"class":1049},".chatroom.",[1032,5963,5964],{"class":1195},"send",[1032,5966,5967],{"class":1049},"(message, ",[1032,5969,2298],{"class":1042},[1032,5971,5972],{"class":1049},", to);\n",[1032,5974,5975],{"class":1034,"line":1124},[1032,5976,1306],{"class":1049},[1032,5978,5979],{"class":1034,"line":1135},[1032,5980,1087],{"emptyLinePlaceholder":1086},[1032,5982,5983,5986,5988,5990,5992,5995],{"class":1034,"line":1140},[1032,5984,5985],{"class":1195},"  receive",[1032,5987,1207],{"class":1049},[1032,5989,5947],{"class":1210},[1032,5991,2819],{"class":1049},[1032,5993,5994],{"class":1210},"from",[1032,5996,1214],{"class":1049},[1032,5998,5999,6001,6003,6006,6008,6011,6013,6015,6017,6019,6022,6024],{"class":1034,"line":1145},[1032,6000,1873],{"class":1049},[1032,6002,1728],{"class":1195},[1032,6004,6005],{"class":1049},"(from.name ",[1032,6007,3910],{"class":1038},[1032,6009,6010],{"class":1059}," ' -> '",[1032,6012,5429],{"class":1038},[1032,6014,1533],{"class":1042},[1032,6016,4791],{"class":1049},[1032,6018,3910],{"class":1038},[1032,6020,6021],{"class":1059}," ': '",[1032,6023,5429],{"class":1038},[1032,6025,6026],{"class":1049}," message);\n",[1032,6028,6029],{"class":1034,"line":1157},[1032,6030,1306],{"class":1049},[1032,6032,6033],{"class":1034,"line":1168},[1032,6034,1312],{"class":1049},[1032,6036,6037],{"class":1034,"line":1179},[1032,6038,1087],{"emptyLinePlaceholder":1086},[1032,6040,6041,6043,6046],{"class":1034,"line":1184},[1032,6042,1192],{"class":1038},[1032,6044,6045],{"class":1195}," Chatroom",[1032,6047,1050],{"class":1049},[1032,6049,6050,6052],{"class":1034,"line":1189},[1032,6051,1204],{"class":1038},[1032,6053,1868],{"class":1049},[1032,6055,6056,6058,6061,6063],{"class":1034,"line":1201},[1032,6057,1220],{"class":1042},[1032,6059,6060],{"class":1049},".participants ",[1032,6062,1226],{"class":1038},[1032,6064,6065],{"class":1049}," {};\n",[1032,6067,6068],{"class":1034,"line":1217},[1032,6069,1306],{"class":1049},[1032,6071,6072],{"class":1034,"line":1232},[1032,6073,1087],{"emptyLinePlaceholder":1086},[1032,6075,6076,6079,6081,6084],{"class":1034,"line":1254},[1032,6077,6078],{"class":1195},"  join",[1032,6080,1207],{"class":1049},[1032,6082,6083],{"class":1210},"participant",[1032,6085,1214],{"class":1049},[1032,6087,6088,6090,6093,6095],{"class":1034,"line":1279},[1032,6089,1220],{"class":1042},[1032,6091,6092],{"class":1049},".participants[participant.name] ",[1032,6094,1226],{"class":1038},[1032,6096,6097],{"class":1049}," participant;\n",[1032,6099,6100,6103,6105,6107],{"class":1034,"line":1303},[1032,6101,6102],{"class":1049},"    participant.chatroom ",[1032,6104,1226],{"class":1038},[1032,6106,1533],{"class":1042},[1032,6108,1251],{"class":1049},[1032,6110,6111],{"class":1034,"line":1309},[1032,6112,1306],{"class":1049},[1032,6114,6115],{"class":1034,"line":1315},[1032,6116,1087],{"emptyLinePlaceholder":1086},[1032,6118,6119,6121,6123,6125,6127,6129,6131,6133],{"class":1034,"line":1320},[1032,6120,5942],{"class":1195},[1032,6122,1207],{"class":1049},[1032,6124,5947],{"class":1210},[1032,6126,2819],{"class":1049},[1032,6128,5994],{"class":1210},[1032,6130,2819],{"class":1049},[1032,6132,5952],{"class":1210},[1032,6134,1214],{"class":1049},[1032,6136,6137,6139],{"class":1034,"line":1330},[1032,6138,3212],{"class":1038},[1032,6140,6141],{"class":1049}," (to) {\n",[1032,6143,6144],{"class":1034,"line":1341},[1032,6145,6146],{"class":1718},"      \u002F\u002F single message\n",[1032,6148,6149,6152,6155],{"class":1034,"line":1352},[1032,6150,6151],{"class":1049},"      to.",[1032,6153,6154],{"class":1195},"receive",[1032,6156,6157],{"class":1049},"(message, from);\n",[1032,6159,6160,6162,6164],{"class":1034,"line":1374},[1032,6161,4903],{"class":1049},[1032,6163,4906],{"class":1038},[1032,6165,1050],{"class":1049},[1032,6167,6168],{"class":1034,"line":1396},[1032,6169,6170],{"class":1718},"      \u002F\u002F broadcast message\n",[1032,6172,6173,6176,6178,6180,6183,6186,6188],{"class":1034,"line":1401},[1032,6174,6175],{"class":1038},"      for",[1032,6177,5359],{"class":1049},[1032,6179,1039],{"class":1038},[1032,6181,6182],{"class":1042}," key",[1032,6184,6185],{"class":1038}," in",[1032,6187,1533],{"class":1042},[1032,6189,6190],{"class":1049},".participants) {\n",[1032,6192,6193,6196,6198,6200,6203,6206],{"class":1034,"line":1406},[1032,6194,6195],{"class":1038},"        if",[1032,6197,5359],{"class":1049},[1032,6199,2298],{"class":1042},[1032,6201,6202],{"class":1049},".participants[key] ",[1032,6204,6205],{"class":1038},"!==",[1032,6207,6208],{"class":1049}," from) {\n",[1032,6210,6211,6214,6217,6219],{"class":1034,"line":1411},[1032,6212,6213],{"class":1042},"          this",[1032,6215,6216],{"class":1049},".participants[key].",[1032,6218,6154],{"class":1195},[1032,6220,6157],{"class":1049},[1032,6222,6223],{"class":1034,"line":1421},[1032,6224,6225],{"class":1049},"        }\n",[1032,6227,6228],{"class":1034,"line":1433},[1032,6229,6230],{"class":1049},"      }\n",[1032,6232,6233],{"class":1034,"line":1442},[1032,6234,1516],{"class":1049},[1032,6236,6237],{"class":1034,"line":1458},[1032,6238,1306],{"class":1049},[1032,6240,6241],{"class":1034,"line":1472},[1032,6242,1312],{"class":1049},[1032,6244,6245],{"class":1034,"line":1480},[1032,6246,1087],{"emptyLinePlaceholder":1086},[1032,6248,6249,6251,6254,6256,6258,6260,6262,6265],{"class":1034,"line":1494},[1032,6250,1039],{"class":1038},[1032,6252,6253],{"class":1042}," michael",[1032,6255,1046],{"class":1038},[1032,6257,1530],{"class":1038},[1032,6259,5893],{"class":1195},[1032,6261,1207],{"class":1049},[1032,6263,6264],{"class":1059},"'Michael'",[1032,6266,1743],{"class":1049},[1032,6268,6269,6271,6274,6276,6278,6280,6282,6285],{"class":1034,"line":1506},[1032,6270,1039],{"class":1038},[1032,6272,6273],{"class":1042}," jane",[1032,6275,1046],{"class":1038},[1032,6277,1530],{"class":1038},[1032,6279,5893],{"class":1195},[1032,6281,1207],{"class":1049},[1032,6283,6284],{"class":1059},"'Jane'",[1032,6286,1743],{"class":1049},[1032,6288,6289,6291,6294,6296,6298,6300,6302,6305],{"class":1034,"line":1513},[1032,6290,1039],{"class":1038},[1032,6292,6293],{"class":1042}," paul",[1032,6295,1046],{"class":1038},[1032,6297,1530],{"class":1038},[1032,6299,5893],{"class":1195},[1032,6301,1207],{"class":1049},[1032,6303,6304],{"class":1059},"'Paul'",[1032,6306,1743],{"class":1049},[1032,6308,6309,6311,6314,6316,6318,6320,6322,6325],{"class":1034,"line":1519},[1032,6310,1039],{"class":1038},[1032,6312,6313],{"class":1042}," emily",[1032,6315,1046],{"class":1038},[1032,6317,1530],{"class":1038},[1032,6319,5893],{"class":1195},[1032,6321,1207],{"class":1049},[1032,6323,6324],{"class":1059},"'Emily'",[1032,6326,1743],{"class":1049},[1032,6328,6329],{"class":1034,"line":1524},[1032,6330,1087],{"emptyLinePlaceholder":1086},[1032,6332,6333,6335,6338,6340,6342,6344],{"class":1034,"line":1544},[1032,6334,1039],{"class":1038},[1032,6336,6337],{"class":1042}," chatroom",[1032,6339,1046],{"class":1038},[1032,6341,1530],{"class":1038},[1032,6343,6045],{"class":1195},[1032,6345,1573],{"class":1049},[1032,6347,6348,6351,6354],{"class":1034,"line":1549},[1032,6349,6350],{"class":1049},"chatroom.",[1032,6352,6353],{"class":1195},"join",[1032,6355,6356],{"class":1049},"(michael);\n",[1032,6358,6359,6361,6363],{"class":1034,"line":1554},[1032,6360,6350],{"class":1049},[1032,6362,6353],{"class":1195},[1032,6364,6365],{"class":1049},"(jane);\n",[1032,6367,6368,6370,6372],{"class":1034,"line":1559},[1032,6369,6350],{"class":1049},[1032,6371,6353],{"class":1195},[1032,6373,6374],{"class":1049},"(paul);\n",[1032,6376,6377,6379,6381],{"class":1034,"line":1576},[1032,6378,6350],{"class":1049},[1032,6380,6353],{"class":1195},[1032,6382,6383],{"class":1049},"(emily);\n",[1032,6385,6386],{"class":1034,"line":1581},[1032,6387,1087],{"emptyLinePlaceholder":1086},[1032,6389,6390,6393,6395,6397,6400],{"class":1034,"line":1600},[1032,6391,6392],{"class":1049},"michael.",[1032,6394,5964],{"class":1195},[1032,6396,1207],{"class":1049},[1032,6398,6399],{"class":1059},"'Hey Jane, how was your weekend?'",[1032,6401,1743],{"class":1049},[1032,6403,6404,6407,6409,6411,6414],{"class":1034,"line":1615},[1032,6405,6406],{"class":1049},"jane.",[1032,6408,5964],{"class":1195},[1032,6410,1207],{"class":1049},[1032,6412,6413],{"class":1059},"'Hey Michael, it was great. How was yours?'",[1032,6415,6416],{"class":1049},", michael);\n",[1032,6418,6419,6422,6424,6426,6429],{"class":1034,"line":1631},[1032,6420,6421],{"class":1049},"paul.",[1032,6423,5964],{"class":1195},[1032,6425,1207],{"class":1049},[1032,6427,6428],{"class":1059},"'Hey peeps, how are we going?'",[1032,6430,1743],{"class":1049},[1032,6432,6433,6436,6438,6440,6443],{"class":1034,"line":1642},[1032,6434,6435],{"class":1049},"emily.",[1032,6437,5964],{"class":1195},[1032,6439,1207],{"class":1049},[1032,6441,6442],{"class":1059},"'Great Paul. Thank you'",[1032,6444,6445],{"class":1049},", paul);\n",[927,6447,6448],{},"Another example of Mediator is that of a control tower on an airport coordinating arrivals and departures of aeroplanes.",[953,6450,6452],{"id":6451},"memento","Memento",[927,6454,2138,6455,6459],{},[967,6456,6457],{},[930,6458,6452],{}," pattern is a behavioral design pattern that restoration of an object to its previous state as well as provides temporary storage. The mechanism in which you store the object’s state depends on the required duration of persistence, which may vary.",[927,6461,6462],{},[948,6463],{"alt":6451,"src":6464},"\u002Fimages\u002Fblog\u002F2021-12-16-javascript-design-patterns\u002Fmemento.png",[927,6466,6467],{},"The memento pattern is implemented with three objects: the originator, a caretaker and a memento.",[927,6469,6470],{},"Let’s look at them individually:",[961,6472,6473,6486,6495],{},[964,6474,6475,6478],{},[967,6476,6477],{},"Originator",[961,6479,6480,6483],{},[964,6481,6482],{},"Implements interface to create and restore mementos of itself",[964,6484,6485],{},"The object whose state is temporary being saved and restored",[964,6487,6488,6490],{},[967,6489,6452],{},[961,6491,6492],{},[964,6493,6494],{},"The internal state of the Originator object in some storage format",[964,6496,6497,6500],{},[967,6498,6499],{},"CareTaker",[961,6501,6502,6505],{},[964,6503,6504],{},"Responsible for storing mementos",[964,6506,6507],{},"Just a repository; does not make changes to mementos",[927,6509,6510,6511,6514,6515,6518],{},"In the example code below, there are two people named John and Emily are being created using the ",[1029,6512,6513],{},"Person"," constructor function. Next, their mementos are created which are maintained by the ",[1029,6516,6517],{},"LocalStorage"," object.",[1022,6520,6522],{"className":1024,"code":6521,"language":1026,"meta":1027,"style":1027},"class Person {\n  constructor(name) {\n    this.name = name;\n  }\n\n  hydrate() {\n    const memento = JSON.stringify(this);\n    return memento;\n  }\n\n  dehydrate(memento) {\n    const m = JSON.parse(memento);\n    this.name = m.name;\n  }\n}\n\n\u002F\u002F CareTaker\nclass LocalStorage {\n  constructor() {\n    this.mementos = {};\n  }\n\n  add(key, memento) {\n    this.mementos[key] = memento;\n  }\n\n  get(key) {\n    return this.mementos[key];\n  }\n}\n\nconst john = new Person('John Doe');\nconst emily = new Person('Emily Smith');\nconst localStorage = new LocalStorage();\n\n\u002F\u002F Save state\nlocalStorage.add(1, john.hydrate());\nlocalStorage.add(2, emily.hydrate());\n\n\u002F\u002F Assign false names\njohn.name = 'Michael Knight';\nemily.name = 'Stephanie Mason';\n\n\u002F\u002F Restore original state\njohn.dehydrate(localStorage.get(1));\nemily.dehydrate(localStorage.get(2));\n\nconsole.log(john.name);\nconsole.log(emily.name);\n",[1029,6523,6524,6533,6543,6553,6557,6561,6568,6591,6598,6602,6606,6617,6636,6647,6651,6655,6659,6664,6673,6679,6690,6694,6698,6713,6724,6728,6732,6743,6752,6756,6760,6764,6784,6803,6818,6822,6827,6847,6864,6868,6873,6885,6897,6901,6906,6926,6942,6946,6955],{"__ignoreMap":1027},[1032,6525,6526,6528,6531],{"class":1034,"line":1035},[1032,6527,1192],{"class":1038},[1032,6529,6530],{"class":1195}," Person",[1032,6532,1050],{"class":1049},[1032,6534,6535,6537,6539,6541],{"class":1034,"line":1053},[1032,6536,1204],{"class":1038},[1032,6538,1207],{"class":1049},[1032,6540,4757],{"class":1210},[1032,6542,1214],{"class":1049},[1032,6544,6545,6547,6549,6551],{"class":1034,"line":1066},[1032,6546,1220],{"class":1042},[1032,6548,4791],{"class":1049},[1032,6550,1226],{"class":1038},[1032,6552,4796],{"class":1049},[1032,6554,6555],{"class":1034,"line":1077},[1032,6556,1306],{"class":1049},[1032,6558,6559],{"class":1034,"line":1083},[1032,6560,1087],{"emptyLinePlaceholder":1086},[1032,6562,6563,6566],{"class":1034,"line":1090},[1032,6564,6565],{"class":1195},"  hydrate",[1032,6567,1868],{"class":1049},[1032,6569,6570,6572,6575,6577,6580,6582,6585,6587,6589],{"class":1034,"line":1102},[1032,6571,3192],{"class":1038},[1032,6573,6574],{"class":1042}," memento",[1032,6576,1046],{"class":1038},[1032,6578,6579],{"class":1042}," JSON",[1032,6581,1271],{"class":1049},[1032,6583,6584],{"class":1195},"stringify",[1032,6586,1207],{"class":1049},[1032,6588,2298],{"class":1042},[1032,6590,1743],{"class":1049},[1032,6592,6593,6595],{"class":1034,"line":1113},[1032,6594,1527],{"class":1038},[1032,6596,6597],{"class":1049}," memento;\n",[1032,6599,6600],{"class":1034,"line":1124},[1032,6601,1306],{"class":1049},[1032,6603,6604],{"class":1034,"line":1135},[1032,6605,1087],{"emptyLinePlaceholder":1086},[1032,6607,6608,6611,6613,6615],{"class":1034,"line":1140},[1032,6609,6610],{"class":1195},"  dehydrate",[1032,6612,1207],{"class":1049},[1032,6614,6451],{"class":1210},[1032,6616,1214],{"class":1049},[1032,6618,6619,6621,6624,6626,6628,6630,6633],{"class":1034,"line":1145},[1032,6620,3192],{"class":1038},[1032,6622,6623],{"class":1042}," m",[1032,6625,1046],{"class":1038},[1032,6627,6579],{"class":1042},[1032,6629,1271],{"class":1049},[1032,6631,6632],{"class":1195},"parse",[1032,6634,6635],{"class":1049},"(memento);\n",[1032,6637,6638,6640,6642,6644],{"class":1034,"line":1157},[1032,6639,1220],{"class":1042},[1032,6641,4791],{"class":1049},[1032,6643,1226],{"class":1038},[1032,6645,6646],{"class":1049}," m.name;\n",[1032,6648,6649],{"class":1034,"line":1168},[1032,6650,1306],{"class":1049},[1032,6652,6653],{"class":1034,"line":1179},[1032,6654,1312],{"class":1049},[1032,6656,6657],{"class":1034,"line":1184},[1032,6658,1087],{"emptyLinePlaceholder":1086},[1032,6660,6661],{"class":1034,"line":1189},[1032,6662,6663],{"class":1718},"\u002F\u002F CareTaker\n",[1032,6665,6666,6668,6671],{"class":1034,"line":1201},[1032,6667,1192],{"class":1038},[1032,6669,6670],{"class":1195}," LocalStorage",[1032,6672,1050],{"class":1049},[1032,6674,6675,6677],{"class":1034,"line":1217},[1032,6676,1204],{"class":1038},[1032,6678,1868],{"class":1049},[1032,6680,6681,6683,6686,6688],{"class":1034,"line":1232},[1032,6682,1220],{"class":1042},[1032,6684,6685],{"class":1049},".mementos ",[1032,6687,1226],{"class":1038},[1032,6689,6065],{"class":1049},[1032,6691,6692],{"class":1034,"line":1254},[1032,6693,1306],{"class":1049},[1032,6695,6696],{"class":1034,"line":1279},[1032,6697,1087],{"emptyLinePlaceholder":1086},[1032,6699,6700,6702,6704,6707,6709,6711],{"class":1034,"line":1303},[1032,6701,3888],{"class":1195},[1032,6703,1207],{"class":1049},[1032,6705,6706],{"class":1210},"key",[1032,6708,2819],{"class":1049},[1032,6710,6451],{"class":1210},[1032,6712,1214],{"class":1049},[1032,6714,6715,6717,6720,6722],{"class":1034,"line":1309},[1032,6716,1220],{"class":1042},[1032,6718,6719],{"class":1049},".mementos[key] ",[1032,6721,1226],{"class":1038},[1032,6723,6597],{"class":1049},[1032,6725,6726],{"class":1034,"line":1315},[1032,6727,1306],{"class":1049},[1032,6729,6730],{"class":1034,"line":1320},[1032,6731,1087],{"emptyLinePlaceholder":1086},[1032,6733,6734,6737,6739,6741],{"class":1034,"line":1330},[1032,6735,6736],{"class":1195},"  get",[1032,6738,1207],{"class":1049},[1032,6740,6706],{"class":1210},[1032,6742,1214],{"class":1049},[1032,6744,6745,6747,6749],{"class":1034,"line":1341},[1032,6746,1527],{"class":1038},[1032,6748,1533],{"class":1042},[1032,6750,6751],{"class":1049},".mementos[key];\n",[1032,6753,6754],{"class":1034,"line":1352},[1032,6755,1306],{"class":1049},[1032,6757,6758],{"class":1034,"line":1374},[1032,6759,1312],{"class":1049},[1032,6761,6762],{"class":1034,"line":1396},[1032,6763,1087],{"emptyLinePlaceholder":1086},[1032,6765,6766,6768,6771,6773,6775,6777,6779,6782],{"class":1034,"line":1401},[1032,6767,1039],{"class":1038},[1032,6769,6770],{"class":1042}," john",[1032,6772,1046],{"class":1038},[1032,6774,1530],{"class":1038},[1032,6776,6530],{"class":1195},[1032,6778,1207],{"class":1049},[1032,6780,6781],{"class":1059},"'John Doe'",[1032,6783,1743],{"class":1049},[1032,6785,6786,6788,6790,6792,6794,6796,6798,6801],{"class":1034,"line":1406},[1032,6787,1039],{"class":1038},[1032,6789,6313],{"class":1042},[1032,6791,1046],{"class":1038},[1032,6793,1530],{"class":1038},[1032,6795,6530],{"class":1195},[1032,6797,1207],{"class":1049},[1032,6799,6800],{"class":1059},"'Emily Smith'",[1032,6802,1743],{"class":1049},[1032,6804,6805,6807,6810,6812,6814,6816],{"class":1034,"line":1411},[1032,6806,1039],{"class":1038},[1032,6808,6809],{"class":1042}," localStorage",[1032,6811,1046],{"class":1038},[1032,6813,1530],{"class":1038},[1032,6815,6670],{"class":1195},[1032,6817,1573],{"class":1049},[1032,6819,6820],{"class":1034,"line":1421},[1032,6821,1087],{"emptyLinePlaceholder":1086},[1032,6823,6824],{"class":1034,"line":1433},[1032,6825,6826],{"class":1718},"\u002F\u002F Save state\n",[1032,6828,6829,6832,6835,6837,6839,6842,6845],{"class":1034,"line":1442},[1032,6830,6831],{"class":1049},"localStorage.",[1032,6833,6834],{"class":1195},"add",[1032,6836,1207],{"class":1049},[1032,6838,5057],{"class":1042},[1032,6840,6841],{"class":1049},", john.",[1032,6843,6844],{"class":1195},"hydrate",[1032,6846,2728],{"class":1049},[1032,6848,6849,6851,6853,6855,6857,6860,6862],{"class":1034,"line":1458},[1032,6850,6831],{"class":1049},[1032,6852,6834],{"class":1195},[1032,6854,1207],{"class":1049},[1032,6856,4527],{"class":1042},[1032,6858,6859],{"class":1049},", emily.",[1032,6861,6844],{"class":1195},[1032,6863,2728],{"class":1049},[1032,6865,6866],{"class":1034,"line":1472},[1032,6867,1087],{"emptyLinePlaceholder":1086},[1032,6869,6870],{"class":1034,"line":1480},[1032,6871,6872],{"class":1718},"\u002F\u002F Assign false names\n",[1032,6874,6875,6878,6880,6883],{"class":1034,"line":1494},[1032,6876,6877],{"class":1049},"john.name ",[1032,6879,1226],{"class":1038},[1032,6881,6882],{"class":1059}," 'Michael Knight'",[1032,6884,1251],{"class":1049},[1032,6886,6887,6890,6892,6895],{"class":1034,"line":1506},[1032,6888,6889],{"class":1049},"emily.name ",[1032,6891,1226],{"class":1038},[1032,6893,6894],{"class":1059}," 'Stephanie Mason'",[1032,6896,1251],{"class":1049},[1032,6898,6899],{"class":1034,"line":1513},[1032,6900,1087],{"emptyLinePlaceholder":1086},[1032,6902,6903],{"class":1034,"line":1519},[1032,6904,6905],{"class":1718},"\u002F\u002F Restore original state\n",[1032,6907,6908,6911,6914,6917,6920,6922,6924],{"class":1034,"line":1524},[1032,6909,6910],{"class":1049},"john.",[1032,6912,6913],{"class":1195},"dehydrate",[1032,6915,6916],{"class":1049},"(localStorage.",[1032,6918,6919],{"class":1195},"get",[1032,6921,1207],{"class":1049},[1032,6923,5057],{"class":1042},[1032,6925,4509],{"class":1049},[1032,6927,6928,6930,6932,6934,6936,6938,6940],{"class":1034,"line":1544},[1032,6929,6435],{"class":1049},[1032,6931,6913],{"class":1195},[1032,6933,6916],{"class":1049},[1032,6935,6919],{"class":1195},[1032,6937,1207],{"class":1049},[1032,6939,4527],{"class":1042},[1032,6941,4509],{"class":1049},[1032,6943,6944],{"class":1034,"line":1549},[1032,6945,1087],{"emptyLinePlaceholder":1086},[1032,6947,6948,6950,6952],{"class":1034,"line":1554},[1032,6949,1725],{"class":1049},[1032,6951,1728],{"class":1195},[1032,6953,6954],{"class":1049},"(john.name);\n",[1032,6956,6957,6959,6961],{"class":1034,"line":1559},[1032,6958,1725],{"class":1049},[1032,6960,1728],{"class":1195},[1032,6962,6963],{"class":1049},"(emily.name);\n",[927,6965,6966],{},"We assign John and Emily fake names before restoring them from their mementos. Following the restoration, we confirm that the person objects are back to their original state with valid names.",[953,6968,6970],{"id":6969},"observer","Observer",[927,6972,2138,6973,6977,6978,6982],{},[967,6974,6975],{},[930,6976,6970],{}," pattern is a behavioral design pattern that allows a number of observer objects to see an event. In another word, the ",[967,6979,6980],{},[930,6981,6970],{}," pattern offers a subscription model in which objects subscribe to an event and get notified when the event occurs.",[927,6984,6985],{},[948,6986],{"alt":6970,"src":6987},"\u002Fimages\u002Fblog\u002F2021-12-16-javascript-design-patterns\u002Fobserver.png",[927,6989,6990],{},"The observer pattern in which an object, named the subject, maintains a list of its dependents, called observers, and notifies them automatically of any state changes, usually by calling one of their methods.",[927,6992,6993],{},"Let’s look at the participating objects individually:",[961,6995,6996,7018],{},[964,6997,6998,7001],{},[967,6999,7000],{},"Subject",[961,7002,7003,7006,7009,7012],{},[964,7004,7005],{},"maintains list of observers. Any number of Observer objects may observe a Subject",[964,7007,7008],{},"implements an interface that lets observer objects subscribe or unsubscribe",[964,7010,7011],{},"sends a notification to its observers when its state changes",[964,7013,7014,7017],{},[1029,7015,7016],{},"Event"," class in the example code",[964,7019,7020,7023],{},[967,7021,7022],{},"Observers",[961,7024,7025,7028],{},[964,7026,7027],{},"has a function signature that can be invoked when Subject changes (i.e. event occurs)",[964,7029,7030,7033],{},[1029,7031,7032],{},"handleClick"," function in the example code",[927,7035,7036,7037,7039,7040,7042],{},"In our example below, the ",[1029,7038,7016],{}," class represents the Subject. The ",[1029,7041,7032],{}," function is the subscribing Observer. This handler subscribes, unsubscribes, and then subscribes it while events are firing. It gets notified only of events #1 and #3.",[1022,7044,7046],{"className":1024,"code":7045,"language":1026,"meta":1027,"style":1027},"const window = global; \u002F\u002F because we run in Node.js not the browser\n\nclass Event {\n  constructor() {\n    this.handlers = []; \u002F\u002F observers\n  }\n\n  subscribe(fn) {\n    this.handlers.push(fn);\n  }\n\n  unsubscribe(fn) {\n    this.handlers = this.handlers.filter(function (item) {\n      if (item !== fn) {\n        return item;\n      }\n    });\n  }\n\n  fire(eventDetails, context) {\n    const scope = context || window;\n\n    this.handlers.forEach(function (item) {\n      item.call(scope, eventDetails);\n    });\n  }\n}\n\nconst handleClick = function (item) {\n  console.log('fired: ' + item);\n};\n\nconst event = new Event();\n\nevent.subscribe(handleClick);\nevent.fire('event #1');\nevent.unsubscribe(handleClick);\nevent.fire('event #2');\nevent.subscribe(handleClick);\nevent.fire('event #3');\n",[1029,7047,7048,7063,7067,7076,7082,7097,7101,7105,7117,7129,7133,7137,7148,7173,7186,7194,7198,7203,7207,7211,7227,7245,7249,7268,7279,7283,7287,7291,7295,7313,7329,7333,7337,7352,7356,7367,7381,7390,7403,7411],{"__ignoreMap":1027},[1032,7049,7050,7052,7055,7057,7060],{"class":1034,"line":1035},[1032,7051,1039],{"class":1038},[1032,7053,7054],{"class":1042}," window",[1032,7056,1046],{"class":1038},[1032,7058,7059],{"class":1049}," global; ",[1032,7061,7062],{"class":1718},"\u002F\u002F because we run in Node.js not the browser\n",[1032,7064,7065],{"class":1034,"line":1053},[1032,7066,1087],{"emptyLinePlaceholder":1086},[1032,7068,7069,7071,7074],{"class":1034,"line":1066},[1032,7070,1192],{"class":1038},[1032,7072,7073],{"class":1195}," Event",[1032,7075,1050],{"class":1049},[1032,7077,7078,7080],{"class":1034,"line":1077},[1032,7079,1204],{"class":1038},[1032,7081,1868],{"class":1049},[1032,7083,7084,7086,7089,7091,7094],{"class":1034,"line":1083},[1032,7085,1220],{"class":1042},[1032,7087,7088],{"class":1049},".handlers ",[1032,7090,1226],{"class":1038},[1032,7092,7093],{"class":1049}," []; ",[1032,7095,7096],{"class":1718},"\u002F\u002F observers\n",[1032,7098,7099],{"class":1034,"line":1090},[1032,7100,1306],{"class":1049},[1032,7102,7103],{"class":1034,"line":1102},[1032,7104,1087],{"emptyLinePlaceholder":1086},[1032,7106,7107,7110,7112,7115],{"class":1034,"line":1113},[1032,7108,7109],{"class":1195},"  subscribe",[1032,7111,1207],{"class":1049},[1032,7113,7114],{"class":1210},"fn",[1032,7116,1214],{"class":1049},[1032,7118,7119,7121,7124,7126],{"class":1034,"line":1124},[1032,7120,1220],{"class":1042},[1032,7122,7123],{"class":1049},".handlers.",[1032,7125,3820],{"class":1195},[1032,7127,7128],{"class":1049},"(fn);\n",[1032,7130,7131],{"class":1034,"line":1135},[1032,7132,1306],{"class":1049},[1032,7134,7135],{"class":1034,"line":1140},[1032,7136,1087],{"emptyLinePlaceholder":1086},[1032,7138,7139,7142,7144,7146],{"class":1034,"line":1145},[1032,7140,7141],{"class":1195},"  unsubscribe",[1032,7143,1207],{"class":1049},[1032,7145,7114],{"class":1210},[1032,7147,1214],{"class":1049},[1032,7149,7150,7152,7154,7156,7158,7160,7163,7165,7167,7169,7171],{"class":1034,"line":1157},[1032,7151,1220],{"class":1042},[1032,7153,7088],{"class":1049},[1032,7155,1226],{"class":1038},[1032,7157,1533],{"class":1042},[1032,7159,7123],{"class":1049},[1032,7161,7162],{"class":1195},"filter",[1032,7164,1207],{"class":1049},[1032,7166,5812],{"class":1038},[1032,7168,5359],{"class":1049},[1032,7170,5817],{"class":1210},[1032,7172,1214],{"class":1049},[1032,7174,7175,7178,7181,7183],{"class":1034,"line":1168},[1032,7176,7177],{"class":1038},"      if",[1032,7179,7180],{"class":1049}," (item ",[1032,7182,6205],{"class":1038},[1032,7184,7185],{"class":1049}," fn) {\n",[1032,7187,7188,7191],{"class":1034,"line":1179},[1032,7189,7190],{"class":1038},"        return",[1032,7192,7193],{"class":1049}," item;\n",[1032,7195,7196],{"class":1034,"line":1184},[1032,7197,6230],{"class":1049},[1032,7199,7200],{"class":1034,"line":1189},[1032,7201,7202],{"class":1049},"    });\n",[1032,7204,7205],{"class":1034,"line":1201},[1032,7206,1306],{"class":1049},[1032,7208,7209],{"class":1034,"line":1217},[1032,7210,1087],{"emptyLinePlaceholder":1086},[1032,7212,7213,7216,7218,7221,7223,7225],{"class":1034,"line":1232},[1032,7214,7215],{"class":1195},"  fire",[1032,7217,1207],{"class":1049},[1032,7219,7220],{"class":1210},"eventDetails",[1032,7222,2819],{"class":1049},[1032,7224,4874],{"class":1210},[1032,7226,1214],{"class":1049},[1032,7228,7229,7231,7234,7236,7239,7242],{"class":1034,"line":1254},[1032,7230,3192],{"class":1038},[1032,7232,7233],{"class":1042}," scope",[1032,7235,1046],{"class":1038},[1032,7237,7238],{"class":1049}," context ",[1032,7240,7241],{"class":1038},"||",[1032,7243,7244],{"class":1049}," window;\n",[1032,7246,7247],{"class":1034,"line":1279},[1032,7248,1087],{"emptyLinePlaceholder":1086},[1032,7250,7251,7253,7255,7258,7260,7262,7264,7266],{"class":1034,"line":1303},[1032,7252,1220],{"class":1042},[1032,7254,7123],{"class":1049},[1032,7256,7257],{"class":1195},"forEach",[1032,7259,1207],{"class":1049},[1032,7261,5812],{"class":1038},[1032,7263,5359],{"class":1049},[1032,7265,5817],{"class":1210},[1032,7267,1214],{"class":1049},[1032,7269,7270,7273,7276],{"class":1034,"line":1309},[1032,7271,7272],{"class":1049},"      item.",[1032,7274,7275],{"class":1195},"call",[1032,7277,7278],{"class":1049},"(scope, eventDetails);\n",[1032,7280,7281],{"class":1034,"line":1315},[1032,7282,7202],{"class":1049},[1032,7284,7285],{"class":1034,"line":1320},[1032,7286,1306],{"class":1049},[1032,7288,7289],{"class":1034,"line":1330},[1032,7290,1312],{"class":1049},[1032,7292,7293],{"class":1034,"line":1341},[1032,7294,1087],{"emptyLinePlaceholder":1086},[1032,7296,7297,7299,7302,7304,7307,7309,7311],{"class":1034,"line":1352},[1032,7298,1039],{"class":1038},[1032,7300,7301],{"class":1195}," handleClick",[1032,7303,1046],{"class":1038},[1032,7305,7306],{"class":1038}," function",[1032,7308,5359],{"class":1049},[1032,7310,5817],{"class":1210},[1032,7312,1214],{"class":1049},[1032,7314,7315,7317,7319,7321,7324,7326],{"class":1034,"line":1374},[1032,7316,5824],{"class":1049},[1032,7318,1728],{"class":1195},[1032,7320,1207],{"class":1049},[1032,7322,7323],{"class":1059},"'fired: '",[1032,7325,5429],{"class":1038},[1032,7327,7328],{"class":1049}," item);\n",[1032,7330,7331],{"class":1034,"line":1396},[1032,7332,1080],{"class":1049},[1032,7334,7335],{"class":1034,"line":1401},[1032,7336,1087],{"emptyLinePlaceholder":1086},[1032,7338,7339,7341,7344,7346,7348,7350],{"class":1034,"line":1406},[1032,7340,1039],{"class":1038},[1032,7342,7343],{"class":1042}," event",[1032,7345,1046],{"class":1038},[1032,7347,1530],{"class":1038},[1032,7349,7073],{"class":1195},[1032,7351,1573],{"class":1049},[1032,7353,7354],{"class":1034,"line":1411},[1032,7355,1087],{"emptyLinePlaceholder":1086},[1032,7357,7358,7361,7364],{"class":1034,"line":1421},[1032,7359,7360],{"class":1049},"event.",[1032,7362,7363],{"class":1195},"subscribe",[1032,7365,7366],{"class":1049},"(handleClick);\n",[1032,7368,7369,7371,7374,7376,7379],{"class":1034,"line":1433},[1032,7370,7360],{"class":1049},[1032,7372,7373],{"class":1195},"fire",[1032,7375,1207],{"class":1049},[1032,7377,7378],{"class":1059},"'event #1'",[1032,7380,1743],{"class":1049},[1032,7382,7383,7385,7388],{"class":1034,"line":1442},[1032,7384,7360],{"class":1049},[1032,7386,7387],{"class":1195},"unsubscribe",[1032,7389,7366],{"class":1049},[1032,7391,7392,7394,7396,7398,7401],{"class":1034,"line":1458},[1032,7393,7360],{"class":1049},[1032,7395,7373],{"class":1195},[1032,7397,1207],{"class":1049},[1032,7399,7400],{"class":1059},"'event #2'",[1032,7402,1743],{"class":1049},[1032,7404,7405,7407,7409],{"class":1034,"line":1472},[1032,7406,7360],{"class":1049},[1032,7408,7363],{"class":1195},[1032,7410,7366],{"class":1049},[1032,7412,7413,7415,7417,7419,7422],{"class":1034,"line":1480},[1032,7414,7360],{"class":1049},[1032,7416,7373],{"class":1195},[1032,7418,1207],{"class":1049},[1032,7420,7421],{"class":1059},"'event #3'",[1032,7423,1743],{"class":1049},[927,7425,7426,7427,7429,7430,7432,7433,7435],{},"Notice that the ",[1029,7428,7373],{}," method accepts two arguments. The first one has details about the event and the second one is the context, that is, the ",[1029,7431,2298],{}," value for when the event handlers are called. If no context is provided ",[1029,7434,2298],{}," will be bound to the global object (window).",[953,7437,7439],{"id":7438},"state","State",[927,7441,2741,7442,7446],{},[967,7443,7444],{},[930,7445,7439],{}," pattern is a behavioral software design pattern that allows an object to alter its behavior when its internal state changes. This pattern is close to the concept of finite-state machines.",[927,7448,7449],{},[948,7450],{"alt":7439,"src":7451},"\u002Fimages\u002Fblog\u002F2021-12-16-javascript-design-patterns\u002Fstate.png",[927,7453,2138,7454,7458],{},[967,7455,7456],{},[930,7457,7439],{}," pattern provides state-specific logic to a limited set of objects in which each object represents a particular state.",[927,7460,7461,7462,5466,7465,7468,7469,7472],{},"Our example is a traffic light with 3 different states: ",[1029,7463,7464],{},"Red",[1029,7466,7467],{},"Yellow"," and ",[1029,7470,7471],{},"Green",", each with its own set of rules. The rules go like this: Say the traffic light is Red. After a delay the Red state changes to the Green state. Then, after another delay, the Green state changes to the Yellow state. After a very brief delay, the Yellow state is changed to Red. And on and on.",[1022,7474,7476],{"className":1024,"code":7475,"language":1026,"meta":1027,"style":1027},"class Red {\n  constructor(light) {\n    this.light = light;\n  }\n\n  go() {\n    console.log('Red -> for 1 minute');\n    light.change(new Green(light));\n  }\n}\n\nclass Yellow {\n  constructor(light) {\n    this.light = light;\n  }\n\n  go() {\n    console.log('Yellow -> for 10 seconds');\n    light.change(new Red(light));\n  }\n}\n\nclass Green {\n  constructor(light) {\n    this.light = light;\n  }\n\n  go() {\n    console.log('Green -> for 1 minute');\n    light.change(new Red(light));\n  }\n}\n\nclass TrafficLight {\n  constructor() {\n    this.count = 0;\n    this.currentState = new Red(this);\n  }\n\n  change(state) {\n    \u002F\u002F Limits number of changes\n    if (this.count++ >= 10) return;\n    this.currentState = state;\n    this.currentState.go();\n  }\n\n  start() {\n    this.currentState.go();\n  }\n}\n\nconst light = new TrafficLight();\nlight.start();\n",[1029,7477,7478,7487,7498,7510,7514,7518,7525,7538,7556,7560,7564,7568,7577,7587,7597,7601,7605,7611,7624,7638,7642,7646,7650,7658,7668,7678,7682,7686,7692,7705,7719,7723,7727,7731,7740,7746,7759,7778,7782,7786,7797,7802,7828,7839,7851,7855,7859,7866,7876,7880,7884,7888,7903],{"__ignoreMap":1027},[1032,7479,7480,7482,7485],{"class":1034,"line":1035},[1032,7481,1192],{"class":1038},[1032,7483,7484],{"class":1195}," Red",[1032,7486,1050],{"class":1049},[1032,7488,7489,7491,7493,7496],{"class":1034,"line":1053},[1032,7490,1204],{"class":1038},[1032,7492,1207],{"class":1049},[1032,7494,7495],{"class":1210},"light",[1032,7497,1214],{"class":1049},[1032,7499,7500,7502,7505,7507],{"class":1034,"line":1066},[1032,7501,1220],{"class":1042},[1032,7503,7504],{"class":1049},".light ",[1032,7506,1226],{"class":1038},[1032,7508,7509],{"class":1049}," light;\n",[1032,7511,7512],{"class":1034,"line":1077},[1032,7513,1306],{"class":1049},[1032,7515,7516],{"class":1034,"line":1083},[1032,7517,1087],{"emptyLinePlaceholder":1086},[1032,7519,7520,7523],{"class":1034,"line":1090},[1032,7521,7522],{"class":1195},"  go",[1032,7524,1868],{"class":1049},[1032,7526,7527,7529,7531,7533,7536],{"class":1034,"line":1102},[1032,7528,1873],{"class":1049},[1032,7530,1728],{"class":1195},[1032,7532,1207],{"class":1049},[1032,7534,7535],{"class":1059},"'Red -> for 1 minute'",[1032,7537,1743],{"class":1049},[1032,7539,7540,7543,7546,7548,7550,7553],{"class":1034,"line":1113},[1032,7541,7542],{"class":1049},"    light.",[1032,7544,7545],{"class":1195},"change",[1032,7547,1207],{"class":1049},[1032,7549,4500],{"class":1038},[1032,7551,7552],{"class":1195}," Green",[1032,7554,7555],{"class":1049},"(light));\n",[1032,7557,7558],{"class":1034,"line":1124},[1032,7559,1306],{"class":1049},[1032,7561,7562],{"class":1034,"line":1135},[1032,7563,1312],{"class":1049},[1032,7565,7566],{"class":1034,"line":1140},[1032,7567,1087],{"emptyLinePlaceholder":1086},[1032,7569,7570,7572,7575],{"class":1034,"line":1145},[1032,7571,1192],{"class":1038},[1032,7573,7574],{"class":1195}," Yellow",[1032,7576,1050],{"class":1049},[1032,7578,7579,7581,7583,7585],{"class":1034,"line":1157},[1032,7580,1204],{"class":1038},[1032,7582,1207],{"class":1049},[1032,7584,7495],{"class":1210},[1032,7586,1214],{"class":1049},[1032,7588,7589,7591,7593,7595],{"class":1034,"line":1168},[1032,7590,1220],{"class":1042},[1032,7592,7504],{"class":1049},[1032,7594,1226],{"class":1038},[1032,7596,7509],{"class":1049},[1032,7598,7599],{"class":1034,"line":1179},[1032,7600,1306],{"class":1049},[1032,7602,7603],{"class":1034,"line":1184},[1032,7604,1087],{"emptyLinePlaceholder":1086},[1032,7606,7607,7609],{"class":1034,"line":1189},[1032,7608,7522],{"class":1195},[1032,7610,1868],{"class":1049},[1032,7612,7613,7615,7617,7619,7622],{"class":1034,"line":1201},[1032,7614,1873],{"class":1049},[1032,7616,1728],{"class":1195},[1032,7618,1207],{"class":1049},[1032,7620,7621],{"class":1059},"'Yellow -> for 10 seconds'",[1032,7623,1743],{"class":1049},[1032,7625,7626,7628,7630,7632,7634,7636],{"class":1034,"line":1217},[1032,7627,7542],{"class":1049},[1032,7629,7545],{"class":1195},[1032,7631,1207],{"class":1049},[1032,7633,4500],{"class":1038},[1032,7635,7484],{"class":1195},[1032,7637,7555],{"class":1049},[1032,7639,7640],{"class":1034,"line":1232},[1032,7641,1306],{"class":1049},[1032,7643,7644],{"class":1034,"line":1254},[1032,7645,1312],{"class":1049},[1032,7647,7648],{"class":1034,"line":1279},[1032,7649,1087],{"emptyLinePlaceholder":1086},[1032,7651,7652,7654,7656],{"class":1034,"line":1303},[1032,7653,1192],{"class":1038},[1032,7655,7552],{"class":1195},[1032,7657,1050],{"class":1049},[1032,7659,7660,7662,7664,7666],{"class":1034,"line":1309},[1032,7661,1204],{"class":1038},[1032,7663,1207],{"class":1049},[1032,7665,7495],{"class":1210},[1032,7667,1214],{"class":1049},[1032,7669,7670,7672,7674,7676],{"class":1034,"line":1315},[1032,7671,1220],{"class":1042},[1032,7673,7504],{"class":1049},[1032,7675,1226],{"class":1038},[1032,7677,7509],{"class":1049},[1032,7679,7680],{"class":1034,"line":1320},[1032,7681,1306],{"class":1049},[1032,7683,7684],{"class":1034,"line":1330},[1032,7685,1087],{"emptyLinePlaceholder":1086},[1032,7687,7688,7690],{"class":1034,"line":1341},[1032,7689,7522],{"class":1195},[1032,7691,1868],{"class":1049},[1032,7693,7694,7696,7698,7700,7703],{"class":1034,"line":1352},[1032,7695,1873],{"class":1049},[1032,7697,1728],{"class":1195},[1032,7699,1207],{"class":1049},[1032,7701,7702],{"class":1059},"'Green -> for 1 minute'",[1032,7704,1743],{"class":1049},[1032,7706,7707,7709,7711,7713,7715,7717],{"class":1034,"line":1374},[1032,7708,7542],{"class":1049},[1032,7710,7545],{"class":1195},[1032,7712,1207],{"class":1049},[1032,7714,4500],{"class":1038},[1032,7716,7484],{"class":1195},[1032,7718,7555],{"class":1049},[1032,7720,7721],{"class":1034,"line":1396},[1032,7722,1306],{"class":1049},[1032,7724,7725],{"class":1034,"line":1401},[1032,7726,1312],{"class":1049},[1032,7728,7729],{"class":1034,"line":1406},[1032,7730,1087],{"emptyLinePlaceholder":1086},[1032,7732,7733,7735,7738],{"class":1034,"line":1411},[1032,7734,1192],{"class":1038},[1032,7736,7737],{"class":1195}," TrafficLight",[1032,7739,1050],{"class":1049},[1032,7741,7742,7744],{"class":1034,"line":1421},[1032,7743,1204],{"class":1038},[1032,7745,1868],{"class":1049},[1032,7747,7748,7750,7753,7755,7757],{"class":1034,"line":1433},[1032,7749,1220],{"class":1042},[1032,7751,7752],{"class":1049},".count ",[1032,7754,1226],{"class":1038},[1032,7756,3756],{"class":1042},[1032,7758,1251],{"class":1049},[1032,7760,7761,7763,7766,7768,7770,7772,7774,7776],{"class":1034,"line":1442},[1032,7762,1220],{"class":1042},[1032,7764,7765],{"class":1049},".currentState ",[1032,7767,1226],{"class":1038},[1032,7769,1530],{"class":1038},[1032,7771,7484],{"class":1195},[1032,7773,1207],{"class":1049},[1032,7775,2298],{"class":1042},[1032,7777,1743],{"class":1049},[1032,7779,7780],{"class":1034,"line":1458},[1032,7781,1306],{"class":1049},[1032,7783,7784],{"class":1034,"line":1472},[1032,7785,1087],{"emptyLinePlaceholder":1086},[1032,7787,7788,7791,7793,7795],{"class":1034,"line":1480},[1032,7789,7790],{"class":1195},"  change",[1032,7792,1207],{"class":1049},[1032,7794,7438],{"class":1210},[1032,7796,1214],{"class":1049},[1032,7798,7799],{"class":1034,"line":1494},[1032,7800,7801],{"class":1718},"    \u002F\u002F Limits number of changes\n",[1032,7803,7804,7806,7808,7810,7813,7815,7818,7821,7823,7826],{"class":1034,"line":1506},[1032,7805,3212],{"class":1038},[1032,7807,5359],{"class":1049},[1032,7809,2298],{"class":1042},[1032,7811,7812],{"class":1049},".count",[1032,7814,5391],{"class":1038},[1032,7816,7817],{"class":1038}," >=",[1032,7819,7820],{"class":1042}," 10",[1032,7822,4722],{"class":1049},[1032,7824,7825],{"class":1038},"return",[1032,7827,1251],{"class":1049},[1032,7829,7830,7832,7834,7836],{"class":1034,"line":1513},[1032,7831,1220],{"class":1042},[1032,7833,7765],{"class":1049},[1032,7835,1226],{"class":1038},[1032,7837,7838],{"class":1049}," state;\n",[1032,7840,7841,7843,7846,7849],{"class":1034,"line":1519},[1032,7842,1220],{"class":1042},[1032,7844,7845],{"class":1049},".currentState.",[1032,7847,7848],{"class":1195},"go",[1032,7850,1573],{"class":1049},[1032,7852,7853],{"class":1034,"line":1524},[1032,7854,1306],{"class":1049},[1032,7856,7857],{"class":1034,"line":1544},[1032,7858,1087],{"emptyLinePlaceholder":1086},[1032,7860,7861,7864],{"class":1034,"line":1549},[1032,7862,7863],{"class":1195},"  start",[1032,7865,1868],{"class":1049},[1032,7867,7868,7870,7872,7874],{"class":1034,"line":1554},[1032,7869,1220],{"class":1042},[1032,7871,7845],{"class":1049},[1032,7873,7848],{"class":1195},[1032,7875,1573],{"class":1049},[1032,7877,7878],{"class":1034,"line":1559},[1032,7879,1306],{"class":1049},[1032,7881,7882],{"class":1034,"line":1576},[1032,7883,1312],{"class":1049},[1032,7885,7886],{"class":1034,"line":1581},[1032,7887,1087],{"emptyLinePlaceholder":1086},[1032,7889,7890,7892,7895,7897,7899,7901],{"class":1034,"line":1600},[1032,7891,1039],{"class":1038},[1032,7893,7894],{"class":1042}," light",[1032,7896,1046],{"class":1038},[1032,7898,1530],{"class":1038},[1032,7900,7737],{"class":1195},[1032,7902,1573],{"class":1049},[1032,7904,7905,7908,7911],{"class":1034,"line":1615},[1032,7906,7907],{"class":1049},"light.",[1032,7909,7910],{"class":1195},"start",[1032,7912,1573],{"class":1049},[927,7914,7915],{},"Two other examples where the State pattern is useful include: elevator logic which moves riders up or down depending on certain complex rules that attempt to minimize wait and ride times, and vending machines that dispense products when a correct combination of coins is entered.",[953,7917,7919],{"id":7918},"strategy","Strategy",[927,7921,2741,7922,7926],{},[967,7923,7924],{},[930,7925,7919],{}," pattern is a behavioral design pattern that enables selecting an algorithm at runtime. Instead of implementing a single algorithm directly, code receives run-time instructions as to which in a family of algorithms to use.",[927,7928,7929],{},[948,7930],{"alt":7919,"src":7931},"\u002Fimages\u002Fblog\u002F2021-12-16-javascript-design-patterns\u002Fstrategy.png",[927,7933,2138,7934,7938],{},[967,7935,7936],{},[930,7937,7919],{}," pattern encapsulates alternative algorithms (or strategies) for a particular task. It allows a method to be swapped out at runtime by any other method (strategy) without the client realizing it. Essentially, Strategy is a group of algorithms that are interchangeable.",[927,7940,7941],{},"In this example, we have a product order that needs to be shipped from a warehouse to a customer. Different shipping companies are evaluated to determine the best price. This can be useful with shopping carts where customers select their shipping preferences and the selected Strategy returns the estimated cost.",[1022,7943,7945],{"className":1024,"code":7944,"language":1026,"meta":1027,"style":1027},"class Shipping {\n  constructor() {\n    this.company = '';\n  }\n\n  setStrategy(company) {\n    this.company = company;\n  }\n\n  calculate(pkg) {\n    return this.company.calculate(pkg);\n  }\n}\n\nclass UPS {\n  calculate({ weight }) {\n    const basePrice = 15.26;\n    const total = basePrice * weight;\n\n    return total;\n  }\n}\n\nclass USPS {\n  calculate({ weight }) {\n    const basePrice = 21.21;\n    const total = basePrice * weight;\n\n    return total;\n  }\n}\n\nclass Fedex {\n  calculate({ weight }) {\n    const basePrice = 17.54;\n    const total = basePrice * weight;\n\n    return total;\n  }\n}\n\nconst package = { from: '82563', to: '10400', weight: 2 };\n\nconst ups = new UPS();\nconst usps = new USPS();\nconst fedex = new Fedex();\n\nconst shipping = new Shipping();\n\nshipping.setStrategy(ups);\nconsole.log('UPS Strategy: $' + shipping.calculate(package));\nshipping.setStrategy(usps);\nconsole.log('USPS Strategy: $' + shipping.calculate(package));\nshipping.setStrategy(fedex);\nconsole.log('Fedex Strategy: $' + shipping.calculate(package));\n",[1029,7946,7947,7956,7962,7976,7980,7984,7996,8007,8011,8015,8027,8042,8046,8050,8054,8063,8076,8090,8107,8111,8118,8122,8126,8130,8139,8149,8162,8176,8180,8186,8190,8194,8198,8207,8217,8230,8244,8248,8254,8258,8262,8266,8295,8299,8314,8329,8344,8348,8363,8367,8378,8399,8408,8427,8436],{"__ignoreMap":1027},[1032,7948,7949,7951,7954],{"class":1034,"line":1035},[1032,7950,1192],{"class":1038},[1032,7952,7953],{"class":1195}," Shipping",[1032,7955,1050],{"class":1049},[1032,7957,7958,7960],{"class":1034,"line":1053},[1032,7959,1204],{"class":1038},[1032,7961,1868],{"class":1049},[1032,7963,7964,7966,7969,7971,7974],{"class":1034,"line":1066},[1032,7965,1220],{"class":1042},[1032,7967,7968],{"class":1049},".company ",[1032,7970,1226],{"class":1038},[1032,7972,7973],{"class":1059}," ''",[1032,7975,1251],{"class":1049},[1032,7977,7978],{"class":1034,"line":1077},[1032,7979,1306],{"class":1049},[1032,7981,7982],{"class":1034,"line":1083},[1032,7983,1087],{"emptyLinePlaceholder":1086},[1032,7985,7986,7989,7991,7994],{"class":1034,"line":1090},[1032,7987,7988],{"class":1195},"  setStrategy",[1032,7990,1207],{"class":1049},[1032,7992,7993],{"class":1210},"company",[1032,7995,1214],{"class":1049},[1032,7997,7998,8000,8002,8004],{"class":1034,"line":1102},[1032,7999,1220],{"class":1042},[1032,8001,7968],{"class":1049},[1032,8003,1226],{"class":1038},[1032,8005,8006],{"class":1049}," company;\n",[1032,8008,8009],{"class":1034,"line":1113},[1032,8010,1306],{"class":1049},[1032,8012,8013],{"class":1034,"line":1124},[1032,8014,1087],{"emptyLinePlaceholder":1086},[1032,8016,8017,8020,8022,8025],{"class":1034,"line":1135},[1032,8018,8019],{"class":1195},"  calculate",[1032,8021,1207],{"class":1049},[1032,8023,8024],{"class":1210},"pkg",[1032,8026,1214],{"class":1049},[1032,8028,8029,8031,8033,8036,8039],{"class":1034,"line":1140},[1032,8030,1527],{"class":1038},[1032,8032,1533],{"class":1042},[1032,8034,8035],{"class":1049},".company.",[1032,8037,8038],{"class":1195},"calculate",[1032,8040,8041],{"class":1049},"(pkg);\n",[1032,8043,8044],{"class":1034,"line":1145},[1032,8045,1306],{"class":1049},[1032,8047,8048],{"class":1034,"line":1157},[1032,8049,1312],{"class":1049},[1032,8051,8052],{"class":1034,"line":1168},[1032,8053,1087],{"emptyLinePlaceholder":1086},[1032,8055,8056,8058,8061],{"class":1034,"line":1179},[1032,8057,1192],{"class":1038},[1032,8059,8060],{"class":1195}," UPS",[1032,8062,1050],{"class":1049},[1032,8064,8065,8067,8070,8073],{"class":1034,"line":1184},[1032,8066,8019],{"class":1195},[1032,8068,8069],{"class":1049},"({ ",[1032,8071,8072],{"class":1210},"weight",[1032,8074,8075],{"class":1049}," }) {\n",[1032,8077,8078,8080,8083,8085,8088],{"class":1034,"line":1189},[1032,8079,3192],{"class":1038},[1032,8081,8082],{"class":1042}," basePrice",[1032,8084,1046],{"class":1038},[1032,8086,8087],{"class":1042}," 15.26",[1032,8089,1251],{"class":1049},[1032,8091,8092,8094,8097,8099,8102,8104],{"class":1034,"line":1201},[1032,8093,3192],{"class":1038},[1032,8095,8096],{"class":1042}," total",[1032,8098,1046],{"class":1038},[1032,8100,8101],{"class":1049}," basePrice ",[1032,8103,3547],{"class":1038},[1032,8105,8106],{"class":1049}," weight;\n",[1032,8108,8109],{"class":1034,"line":1217},[1032,8110,1087],{"emptyLinePlaceholder":1086},[1032,8112,8113,8115],{"class":1034,"line":1232},[1032,8114,1527],{"class":1038},[1032,8116,8117],{"class":1049}," total;\n",[1032,8119,8120],{"class":1034,"line":1254},[1032,8121,1306],{"class":1049},[1032,8123,8124],{"class":1034,"line":1279},[1032,8125,1312],{"class":1049},[1032,8127,8128],{"class":1034,"line":1303},[1032,8129,1087],{"emptyLinePlaceholder":1086},[1032,8131,8132,8134,8137],{"class":1034,"line":1309},[1032,8133,1192],{"class":1038},[1032,8135,8136],{"class":1195}," USPS",[1032,8138,1050],{"class":1049},[1032,8140,8141,8143,8145,8147],{"class":1034,"line":1315},[1032,8142,8019],{"class":1195},[1032,8144,8069],{"class":1049},[1032,8146,8072],{"class":1210},[1032,8148,8075],{"class":1049},[1032,8150,8151,8153,8155,8157,8160],{"class":1034,"line":1320},[1032,8152,3192],{"class":1038},[1032,8154,8082],{"class":1042},[1032,8156,1046],{"class":1038},[1032,8158,8159],{"class":1042}," 21.21",[1032,8161,1251],{"class":1049},[1032,8163,8164,8166,8168,8170,8172,8174],{"class":1034,"line":1330},[1032,8165,3192],{"class":1038},[1032,8167,8096],{"class":1042},[1032,8169,1046],{"class":1038},[1032,8171,8101],{"class":1049},[1032,8173,3547],{"class":1038},[1032,8175,8106],{"class":1049},[1032,8177,8178],{"class":1034,"line":1341},[1032,8179,1087],{"emptyLinePlaceholder":1086},[1032,8181,8182,8184],{"class":1034,"line":1352},[1032,8183,1527],{"class":1038},[1032,8185,8117],{"class":1049},[1032,8187,8188],{"class":1034,"line":1374},[1032,8189,1306],{"class":1049},[1032,8191,8192],{"class":1034,"line":1396},[1032,8193,1312],{"class":1049},[1032,8195,8196],{"class":1034,"line":1401},[1032,8197,1087],{"emptyLinePlaceholder":1086},[1032,8199,8200,8202,8205],{"class":1034,"line":1406},[1032,8201,1192],{"class":1038},[1032,8203,8204],{"class":1195}," Fedex",[1032,8206,1050],{"class":1049},[1032,8208,8209,8211,8213,8215],{"class":1034,"line":1411},[1032,8210,8019],{"class":1195},[1032,8212,8069],{"class":1049},[1032,8214,8072],{"class":1210},[1032,8216,8075],{"class":1049},[1032,8218,8219,8221,8223,8225,8228],{"class":1034,"line":1421},[1032,8220,3192],{"class":1038},[1032,8222,8082],{"class":1042},[1032,8224,1046],{"class":1038},[1032,8226,8227],{"class":1042}," 17.54",[1032,8229,1251],{"class":1049},[1032,8231,8232,8234,8236,8238,8240,8242],{"class":1034,"line":1433},[1032,8233,3192],{"class":1038},[1032,8235,8096],{"class":1042},[1032,8237,1046],{"class":1038},[1032,8239,8101],{"class":1049},[1032,8241,3547],{"class":1038},[1032,8243,8106],{"class":1049},[1032,8245,8246],{"class":1034,"line":1442},[1032,8247,1087],{"emptyLinePlaceholder":1086},[1032,8249,8250,8252],{"class":1034,"line":1458},[1032,8251,1527],{"class":1038},[1032,8253,8117],{"class":1049},[1032,8255,8256],{"class":1034,"line":1472},[1032,8257,1306],{"class":1049},[1032,8259,8260],{"class":1034,"line":1480},[1032,8261,1312],{"class":1049},[1032,8263,8264],{"class":1034,"line":1494},[1032,8265,1087],{"emptyLinePlaceholder":1086},[1032,8267,8268,8270,8273,8275,8278,8281,8284,8287,8290,8292],{"class":1034,"line":1506},[1032,8269,1039],{"class":1038},[1032,8271,8272],{"class":1042}," package",[1032,8274,1046],{"class":1038},[1032,8276,8277],{"class":1049}," { from: ",[1032,8279,8280],{"class":1059},"'82563'",[1032,8282,8283],{"class":1049},", to: ",[1032,8285,8286],{"class":1059},"'10400'",[1032,8288,8289],{"class":1049},", weight: ",[1032,8291,4527],{"class":1042},[1032,8293,8294],{"class":1049}," };\n",[1032,8296,8297],{"class":1034,"line":1513},[1032,8298,1087],{"emptyLinePlaceholder":1086},[1032,8300,8301,8303,8306,8308,8310,8312],{"class":1034,"line":1519},[1032,8302,1039],{"class":1038},[1032,8304,8305],{"class":1042}," ups",[1032,8307,1046],{"class":1038},[1032,8309,1530],{"class":1038},[1032,8311,8060],{"class":1195},[1032,8313,1573],{"class":1049},[1032,8315,8316,8318,8321,8323,8325,8327],{"class":1034,"line":1524},[1032,8317,1039],{"class":1038},[1032,8319,8320],{"class":1042}," usps",[1032,8322,1046],{"class":1038},[1032,8324,1530],{"class":1038},[1032,8326,8136],{"class":1195},[1032,8328,1573],{"class":1049},[1032,8330,8331,8333,8336,8338,8340,8342],{"class":1034,"line":1544},[1032,8332,1039],{"class":1038},[1032,8334,8335],{"class":1042}," fedex",[1032,8337,1046],{"class":1038},[1032,8339,1530],{"class":1038},[1032,8341,8204],{"class":1195},[1032,8343,1573],{"class":1049},[1032,8345,8346],{"class":1034,"line":1549},[1032,8347,1087],{"emptyLinePlaceholder":1086},[1032,8349,8350,8352,8355,8357,8359,8361],{"class":1034,"line":1554},[1032,8351,1039],{"class":1038},[1032,8353,8354],{"class":1042}," shipping",[1032,8356,1046],{"class":1038},[1032,8358,1530],{"class":1038},[1032,8360,7953],{"class":1195},[1032,8362,1573],{"class":1049},[1032,8364,8365],{"class":1034,"line":1559},[1032,8366,1087],{"emptyLinePlaceholder":1086},[1032,8368,8369,8372,8375],{"class":1034,"line":1576},[1032,8370,8371],{"class":1049},"shipping.",[1032,8373,8374],{"class":1195},"setStrategy",[1032,8376,8377],{"class":1049},"(ups);\n",[1032,8379,8380,8382,8384,8386,8389,8391,8394,8396],{"class":1034,"line":1581},[1032,8381,1725],{"class":1049},[1032,8383,1728],{"class":1195},[1032,8385,1207],{"class":1049},[1032,8387,8388],{"class":1059},"'UPS Strategy: $'",[1032,8390,5429],{"class":1038},[1032,8392,8393],{"class":1049}," shipping.",[1032,8395,8038],{"class":1195},[1032,8397,8398],{"class":1049},"(package));\n",[1032,8400,8401,8403,8405],{"class":1034,"line":1600},[1032,8402,8371],{"class":1049},[1032,8404,8374],{"class":1195},[1032,8406,8407],{"class":1049},"(usps);\n",[1032,8409,8410,8412,8414,8416,8419,8421,8423,8425],{"class":1034,"line":1615},[1032,8411,1725],{"class":1049},[1032,8413,1728],{"class":1195},[1032,8415,1207],{"class":1049},[1032,8417,8418],{"class":1059},"'USPS Strategy: $'",[1032,8420,5429],{"class":1038},[1032,8422,8393],{"class":1049},[1032,8424,8038],{"class":1195},[1032,8426,8398],{"class":1049},[1032,8428,8429,8431,8433],{"class":1034,"line":1631},[1032,8430,8371],{"class":1049},[1032,8432,8374],{"class":1195},[1032,8434,8435],{"class":1049},"(fedex);\n",[1032,8437,8438,8440,8442,8444,8447,8449,8451,8453],{"class":1034,"line":1642},[1032,8439,1725],{"class":1049},[1032,8441,1728],{"class":1195},[1032,8443,1207],{"class":1049},[1032,8445,8446],{"class":1059},"'Fedex Strategy: $'",[1032,8448,5429],{"class":1038},[1032,8450,8393],{"class":1049},[1032,8452,8038],{"class":1195},[1032,8454,8398],{"class":1049},[927,8456,8457],{},"In JavaScript the Strategy pattern is widely used as a plug-in mechanism when building extensible frameworks.",[953,8459,8461],{"id":8460},"template-method","Template Method",[927,8463,2741,8464,8468],{},[967,8465,8466],{},[930,8467,8461],{}," is a method in a superclass, usually an abstract superclass, and defines the skeleton of an operation in terms of a number of high-level steps.",[927,8470,8471],{},[948,8472],{"alt":8461,"src":8473},"\u002Fimages\u002Fblog\u002F2021-12-16-javascript-design-patterns\u002Ftemplate-method.png",[927,8475,8476],{},"Template Methods are frequently used in libraries or general-purpose frameworks that will be used by other developers. An example is an object that fires a sequence of events in response to an action, for example, a process request. The object generates a 'preprocess' event, a 'process' event and a 'postprocess' event. The developer has the option to adjust the response immediately before the processing, during the processing and immediately after the processing.",[1022,8478,8480],{"className":1024,"code":8479,"language":1026,"meta":1027,"style":1027},"class Database {\n  process() {\n    this.connect();\n    this.select();\n    this.disconnect();\n    return true;\n  }\n}\n\nclass MySQL extends Database {\n  constructor() {\n    super();\n  }\n}\n\nconst mySql = new MySQL();\n\nmySql.connect = function () {\n  console.log('MySQL: Connect step');\n};\n\nmySql.select = function () {\n  console.log('MySQL: Select step');\n};\n\nmySql.disconnect = function () {\n  console.log('MySQL: Disconnect step');\n};\n\nmySql.process();\n",[1029,8481,8482,8491,8498,8509,8520,8531,8540,8544,8548,8552,8565,8571,8578,8582,8586,8590,8605,8609,8623,8636,8640,8644,8656,8669,8673,8677,8689,8702,8706,8710],{"__ignoreMap":1027},[1032,8483,8484,8486,8489],{"class":1034,"line":1035},[1032,8485,1192],{"class":1038},[1032,8487,8488],{"class":1195}," Database",[1032,8490,1050],{"class":1049},[1032,8492,8493,8496],{"class":1034,"line":1053},[1032,8494,8495],{"class":1195},"  process",[1032,8497,1868],{"class":1049},[1032,8499,8500,8502,8504,8507],{"class":1034,"line":1066},[1032,8501,1220],{"class":1042},[1032,8503,1271],{"class":1049},[1032,8505,8506],{"class":1195},"connect",[1032,8508,1573],{"class":1049},[1032,8510,8511,8513,8515,8518],{"class":1034,"line":1077},[1032,8512,1220],{"class":1042},[1032,8514,1271],{"class":1049},[1032,8516,8517],{"class":1195},"select",[1032,8519,1573],{"class":1049},[1032,8521,8522,8524,8526,8529],{"class":1034,"line":1083},[1032,8523,1220],{"class":1042},[1032,8525,1271],{"class":1049},[1032,8527,8528],{"class":1195},"disconnect",[1032,8530,1573],{"class":1049},[1032,8532,8533,8535,8538],{"class":1034,"line":1090},[1032,8534,1527],{"class":1038},[1032,8536,8537],{"class":1042}," true",[1032,8539,1251],{"class":1049},[1032,8541,8542],{"class":1034,"line":1102},[1032,8543,1306],{"class":1049},[1032,8545,8546],{"class":1034,"line":1113},[1032,8547,1312],{"class":1049},[1032,8549,8550],{"class":1034,"line":1124},[1032,8551,1087],{"emptyLinePlaceholder":1086},[1032,8553,8554,8556,8559,8561,8563],{"class":1034,"line":1135},[1032,8555,1192],{"class":1038},[1032,8557,8558],{"class":1195}," MySQL",[1032,8560,1857],{"class":1038},[1032,8562,8488],{"class":1195},[1032,8564,1050],{"class":1049},[1032,8566,8567,8569],{"class":1034,"line":1140},[1032,8568,1204],{"class":1038},[1032,8570,1868],{"class":1049},[1032,8572,8573,8576],{"class":1034,"line":1145},[1032,8574,8575],{"class":1042},"    super",[1032,8577,1573],{"class":1049},[1032,8579,8580],{"class":1034,"line":1157},[1032,8581,1306],{"class":1049},[1032,8583,8584],{"class":1034,"line":1168},[1032,8585,1312],{"class":1049},[1032,8587,8588],{"class":1034,"line":1179},[1032,8589,1087],{"emptyLinePlaceholder":1086},[1032,8591,8592,8594,8597,8599,8601,8603],{"class":1034,"line":1184},[1032,8593,1039],{"class":1038},[1032,8595,8596],{"class":1042}," mySql",[1032,8598,1046],{"class":1038},[1032,8600,1530],{"class":1038},[1032,8602,8558],{"class":1195},[1032,8604,1573],{"class":1049},[1032,8606,8607],{"class":1034,"line":1189},[1032,8608,1087],{"emptyLinePlaceholder":1086},[1032,8610,8611,8614,8616,8618,8620],{"class":1034,"line":1201},[1032,8612,8613],{"class":1049},"mySql.",[1032,8615,8506],{"class":1195},[1032,8617,1046],{"class":1038},[1032,8619,7306],{"class":1038},[1032,8621,8622],{"class":1049}," () {\n",[1032,8624,8625,8627,8629,8631,8634],{"class":1034,"line":1217},[1032,8626,5824],{"class":1049},[1032,8628,1728],{"class":1195},[1032,8630,1207],{"class":1049},[1032,8632,8633],{"class":1059},"'MySQL: Connect step'",[1032,8635,1743],{"class":1049},[1032,8637,8638],{"class":1034,"line":1232},[1032,8639,1080],{"class":1049},[1032,8641,8642],{"class":1034,"line":1254},[1032,8643,1087],{"emptyLinePlaceholder":1086},[1032,8645,8646,8648,8650,8652,8654],{"class":1034,"line":1279},[1032,8647,8613],{"class":1049},[1032,8649,8517],{"class":1195},[1032,8651,1046],{"class":1038},[1032,8653,7306],{"class":1038},[1032,8655,8622],{"class":1049},[1032,8657,8658,8660,8662,8664,8667],{"class":1034,"line":1303},[1032,8659,5824],{"class":1049},[1032,8661,1728],{"class":1195},[1032,8663,1207],{"class":1049},[1032,8665,8666],{"class":1059},"'MySQL: Select step'",[1032,8668,1743],{"class":1049},[1032,8670,8671],{"class":1034,"line":1309},[1032,8672,1080],{"class":1049},[1032,8674,8675],{"class":1034,"line":1315},[1032,8676,1087],{"emptyLinePlaceholder":1086},[1032,8678,8679,8681,8683,8685,8687],{"class":1034,"line":1320},[1032,8680,8613],{"class":1049},[1032,8682,8528],{"class":1195},[1032,8684,1046],{"class":1038},[1032,8686,7306],{"class":1038},[1032,8688,8622],{"class":1049},[1032,8690,8691,8693,8695,8697,8700],{"class":1034,"line":1330},[1032,8692,5824],{"class":1049},[1032,8694,1728],{"class":1195},[1032,8696,1207],{"class":1049},[1032,8698,8699],{"class":1059},"'MySQL: Disconnect step'",[1032,8701,1743],{"class":1049},[1032,8703,8704],{"class":1034,"line":1341},[1032,8705,1080],{"class":1049},[1032,8707,8708],{"class":1034,"line":1352},[1032,8709,1087],{"emptyLinePlaceholder":1086},[1032,8711,8712,8714,8717],{"class":1034,"line":1374},[1032,8713,8613],{"class":1049},[1032,8715,8716],{"class":1195},"process",[1032,8718,1573],{"class":1049},[927,8720,8721],{},"The template methods allow the client to change the database (MySQL Server, PostgreSQL, etc.) by adjusting (filling in the blanks) only the template methods. The rest, such as the order of the steps, stays the same for any datastore.",[953,8723,8725],{"id":8724},"visitor","Visitor",[927,8727,2741,8728,8732],{},[967,8729,8730],{},[930,8731,8725],{}," design pattern is a way of separating an algorithm from an object structure on which it operates. A practical result of this separation is the ability to add new operations to existing object structures without modifying the structures.",[927,8734,8735],{},[948,8736],{"alt":8725,"src":8737},"\u002Fimages\u002Fblog\u002F2021-12-16-javascript-design-patterns\u002Fvisitor.png",[927,8739,2138,8740,8744],{},[967,8741,8742],{},[930,8743,8725],{}," pattern defines a new operation to a collection of objects without changing the objects themselves. The new logic resides in a separate object called the Visitor.",[927,8746,8747,8748,8751,8752,7468,8755,8758],{},"In this example, three employees are created with the ",[1029,8749,8750],{},"Employee"," constructor function. Each is getting a 10% salary raise and 2 more vacation days. Two visitor objects, ",[1029,8753,8754],{},"ExtraSalary",[1029,8756,8757],{},"ExtraVacation",", make the necessary changes to the employee objects.",[1022,8760,8762],{"className":1024,"code":8761,"language":1026,"meta":1027,"style":1027},"class Employee {\n  constructor(name, salary, vacationDays) {\n    this.name = name;\n    this.salary = salary;\n    this.vacationDays = vacationDays;\n  }\n\n  accept(visitor) {\n    visitor.visit(this);\n  }\n\n  getName() {\n    return this.name;\n  }\n\n  getSalary() {\n    return this.salary;\n  }\n\n  setSalary(salary) {\n    this.salary = salary;\n  }\n\n  getVacationDays() {\n    return this.vacationDays;\n  }\n\n  setVacationDays(days) {\n    this.vacationDays = days;\n  }\n}\n\nclass Salary {\n  visit(employee) {\n    employee.setSalary(employee.getSalary() * 10.1);\n  }\n}\n\nclass Vacation {\n  visit(employee) {\n    employee.setVacationDays(employee.getVacationDays() + 2);\n  }\n}\n\nconst employees = [\n  new Employee('Joe', 100000, 12),\n  new Employee('Jane', 200000, 38),\n  new Employee('Mark', 150000, 41),\n];\n\nconst visitorSalary = new Salary();\nconst visitorVacation = new Vacation();\n\nfor (let i = 0, len = employees.length; i \u003C len; i++) {\n  const employee = employees[i];\n\n  employee.accept(visitorSalary);\n  employee.accept(visitorVacation);\n\n  console.log(\n    `emp.getName() earns $${employee.getSalary()} and gets ${employee.getVacationDays()} vacation days`,\n  );\n}\n",[1029,8763,8764,8773,8793,8803,8815,8827,8831,8835,8846,8860,8864,8868,8875,8884,8888,8892,8899,8908,8912,8916,8927,8937,8941,8945,8952,8961,8965,8969,8981,8992,8996,9000,9004,9013,9025,9049,9053,9057,9061,9070,9080,9101,9105,9109,9113,9125,9150,9172,9195,9199,9203,9218,9233,9237,9270,9283,9287,9298,9307,9311,9320,9350,9355],{"__ignoreMap":1027},[1032,8765,8766,8768,8771],{"class":1034,"line":1035},[1032,8767,1192],{"class":1038},[1032,8769,8770],{"class":1195}," Employee",[1032,8772,1050],{"class":1049},[1032,8774,8775,8777,8779,8781,8783,8786,8788,8791],{"class":1034,"line":1053},[1032,8776,1204],{"class":1038},[1032,8778,1207],{"class":1049},[1032,8780,4757],{"class":1210},[1032,8782,2819],{"class":1049},[1032,8784,8785],{"class":1210},"salary",[1032,8787,2819],{"class":1049},[1032,8789,8790],{"class":1210},"vacationDays",[1032,8792,1214],{"class":1049},[1032,8794,8795,8797,8799,8801],{"class":1034,"line":1066},[1032,8796,1220],{"class":1042},[1032,8798,4791],{"class":1049},[1032,8800,1226],{"class":1038},[1032,8802,4796],{"class":1049},[1032,8804,8805,8807,8810,8812],{"class":1034,"line":1077},[1032,8806,1220],{"class":1042},[1032,8808,8809],{"class":1049},".salary ",[1032,8811,1226],{"class":1038},[1032,8813,8814],{"class":1049}," salary;\n",[1032,8816,8817,8819,8822,8824],{"class":1034,"line":1083},[1032,8818,1220],{"class":1042},[1032,8820,8821],{"class":1049},".vacationDays ",[1032,8823,1226],{"class":1038},[1032,8825,8826],{"class":1049}," vacationDays;\n",[1032,8828,8829],{"class":1034,"line":1090},[1032,8830,1306],{"class":1049},[1032,8832,8833],{"class":1034,"line":1102},[1032,8834,1087],{"emptyLinePlaceholder":1086},[1032,8836,8837,8840,8842,8844],{"class":1034,"line":1113},[1032,8838,8839],{"class":1195},"  accept",[1032,8841,1207],{"class":1049},[1032,8843,8724],{"class":1210},[1032,8845,1214],{"class":1049},[1032,8847,8848,8851,8854,8856,8858],{"class":1034,"line":1124},[1032,8849,8850],{"class":1049},"    visitor.",[1032,8852,8853],{"class":1195},"visit",[1032,8855,1207],{"class":1049},[1032,8857,2298],{"class":1042},[1032,8859,1743],{"class":1049},[1032,8861,8862],{"class":1034,"line":1135},[1032,8863,1306],{"class":1049},[1032,8865,8866],{"class":1034,"line":1140},[1032,8867,1087],{"emptyLinePlaceholder":1086},[1032,8869,8870,8873],{"class":1034,"line":1145},[1032,8871,8872],{"class":1195},"  getName",[1032,8874,1868],{"class":1049},[1032,8876,8877,8879,8881],{"class":1034,"line":1157},[1032,8878,1527],{"class":1038},[1032,8880,1533],{"class":1042},[1032,8882,8883],{"class":1049},".name;\n",[1032,8885,8886],{"class":1034,"line":1168},[1032,8887,1306],{"class":1049},[1032,8889,8890],{"class":1034,"line":1179},[1032,8891,1087],{"emptyLinePlaceholder":1086},[1032,8893,8894,8897],{"class":1034,"line":1184},[1032,8895,8896],{"class":1195},"  getSalary",[1032,8898,1868],{"class":1049},[1032,8900,8901,8903,8905],{"class":1034,"line":1189},[1032,8902,1527],{"class":1038},[1032,8904,1533],{"class":1042},[1032,8906,8907],{"class":1049},".salary;\n",[1032,8909,8910],{"class":1034,"line":1201},[1032,8911,1306],{"class":1049},[1032,8913,8914],{"class":1034,"line":1217},[1032,8915,1087],{"emptyLinePlaceholder":1086},[1032,8917,8918,8921,8923,8925],{"class":1034,"line":1232},[1032,8919,8920],{"class":1195},"  setSalary",[1032,8922,1207],{"class":1049},[1032,8924,8785],{"class":1210},[1032,8926,1214],{"class":1049},[1032,8928,8929,8931,8933,8935],{"class":1034,"line":1254},[1032,8930,1220],{"class":1042},[1032,8932,8809],{"class":1049},[1032,8934,1226],{"class":1038},[1032,8936,8814],{"class":1049},[1032,8938,8939],{"class":1034,"line":1279},[1032,8940,1306],{"class":1049},[1032,8942,8943],{"class":1034,"line":1303},[1032,8944,1087],{"emptyLinePlaceholder":1086},[1032,8946,8947,8950],{"class":1034,"line":1309},[1032,8948,8949],{"class":1195},"  getVacationDays",[1032,8951,1868],{"class":1049},[1032,8953,8954,8956,8958],{"class":1034,"line":1315},[1032,8955,1527],{"class":1038},[1032,8957,1533],{"class":1042},[1032,8959,8960],{"class":1049},".vacationDays;\n",[1032,8962,8963],{"class":1034,"line":1320},[1032,8964,1306],{"class":1049},[1032,8966,8967],{"class":1034,"line":1330},[1032,8968,1087],{"emptyLinePlaceholder":1086},[1032,8970,8971,8974,8976,8979],{"class":1034,"line":1341},[1032,8972,8973],{"class":1195},"  setVacationDays",[1032,8975,1207],{"class":1049},[1032,8977,8978],{"class":1210},"days",[1032,8980,1214],{"class":1049},[1032,8982,8983,8985,8987,8989],{"class":1034,"line":1352},[1032,8984,1220],{"class":1042},[1032,8986,8821],{"class":1049},[1032,8988,1226],{"class":1038},[1032,8990,8991],{"class":1049}," days;\n",[1032,8993,8994],{"class":1034,"line":1374},[1032,8995,1306],{"class":1049},[1032,8997,8998],{"class":1034,"line":1396},[1032,8999,1312],{"class":1049},[1032,9001,9002],{"class":1034,"line":1401},[1032,9003,1087],{"emptyLinePlaceholder":1086},[1032,9005,9006,9008,9011],{"class":1034,"line":1406},[1032,9007,1192],{"class":1038},[1032,9009,9010],{"class":1195}," Salary",[1032,9012,1050],{"class":1049},[1032,9014,9015,9018,9020,9023],{"class":1034,"line":1411},[1032,9016,9017],{"class":1195},"  visit",[1032,9019,1207],{"class":1049},[1032,9021,9022],{"class":1210},"employee",[1032,9024,1214],{"class":1049},[1032,9026,9027,9030,9033,9036,9039,9042,9044,9047],{"class":1034,"line":1421},[1032,9028,9029],{"class":1049},"    employee.",[1032,9031,9032],{"class":1195},"setSalary",[1032,9034,9035],{"class":1049},"(employee.",[1032,9037,9038],{"class":1195},"getSalary",[1032,9040,9041],{"class":1049},"() ",[1032,9043,3547],{"class":1038},[1032,9045,9046],{"class":1042}," 10.1",[1032,9048,1743],{"class":1049},[1032,9050,9051],{"class":1034,"line":1433},[1032,9052,1306],{"class":1049},[1032,9054,9055],{"class":1034,"line":1442},[1032,9056,1312],{"class":1049},[1032,9058,9059],{"class":1034,"line":1458},[1032,9060,1087],{"emptyLinePlaceholder":1086},[1032,9062,9063,9065,9068],{"class":1034,"line":1472},[1032,9064,1192],{"class":1038},[1032,9066,9067],{"class":1195}," Vacation",[1032,9069,1050],{"class":1049},[1032,9071,9072,9074,9076,9078],{"class":1034,"line":1480},[1032,9073,9017],{"class":1195},[1032,9075,1207],{"class":1049},[1032,9077,9022],{"class":1210},[1032,9079,1214],{"class":1049},[1032,9081,9082,9084,9087,9089,9092,9094,9096,9099],{"class":1034,"line":1494},[1032,9083,9029],{"class":1049},[1032,9085,9086],{"class":1195},"setVacationDays",[1032,9088,9035],{"class":1049},[1032,9090,9091],{"class":1195},"getVacationDays",[1032,9093,9041],{"class":1049},[1032,9095,3910],{"class":1038},[1032,9097,9098],{"class":1042}," 2",[1032,9100,1743],{"class":1049},[1032,9102,9103],{"class":1034,"line":1506},[1032,9104,1306],{"class":1049},[1032,9106,9107],{"class":1034,"line":1513},[1032,9108,1312],{"class":1049},[1032,9110,9111],{"class":1034,"line":1519},[1032,9112,1087],{"emptyLinePlaceholder":1086},[1032,9114,9115,9117,9120,9122],{"class":1034,"line":1524},[1032,9116,1039],{"class":1038},[1032,9118,9119],{"class":1042}," employees",[1032,9121,1046],{"class":1038},[1032,9123,9124],{"class":1049}," [\n",[1032,9126,9127,9130,9132,9134,9137,9139,9142,9144,9147],{"class":1034,"line":1544},[1032,9128,9129],{"class":1038},"  new",[1032,9131,8770],{"class":1195},[1032,9133,1207],{"class":1049},[1032,9135,9136],{"class":1059},"'Joe'",[1032,9138,2819],{"class":1049},[1032,9140,9141],{"class":1042},"100000",[1032,9143,2819],{"class":1049},[1032,9145,9146],{"class":1042},"12",[1032,9148,9149],{"class":1049},"),\n",[1032,9151,9152,9154,9156,9158,9160,9162,9165,9167,9170],{"class":1034,"line":1549},[1032,9153,9129],{"class":1038},[1032,9155,8770],{"class":1195},[1032,9157,1207],{"class":1049},[1032,9159,6284],{"class":1059},[1032,9161,2819],{"class":1049},[1032,9163,9164],{"class":1042},"200000",[1032,9166,2819],{"class":1049},[1032,9168,9169],{"class":1042},"38",[1032,9171,9149],{"class":1049},[1032,9173,9174,9176,9178,9180,9183,9185,9188,9190,9193],{"class":1034,"line":1554},[1032,9175,9129],{"class":1038},[1032,9177,8770],{"class":1195},[1032,9179,1207],{"class":1049},[1032,9181,9182],{"class":1059},"'Mark'",[1032,9184,2819],{"class":1049},[1032,9186,9187],{"class":1042},"150000",[1032,9189,2819],{"class":1049},[1032,9191,9192],{"class":1042},"41",[1032,9194,9149],{"class":1049},[1032,9196,9197],{"class":1034,"line":1559},[1032,9198,5600],{"class":1049},[1032,9200,9201],{"class":1034,"line":1576},[1032,9202,1087],{"emptyLinePlaceholder":1086},[1032,9204,9205,9207,9210,9212,9214,9216],{"class":1034,"line":1581},[1032,9206,1039],{"class":1038},[1032,9208,9209],{"class":1042}," visitorSalary",[1032,9211,1046],{"class":1038},[1032,9213,1530],{"class":1038},[1032,9215,9010],{"class":1195},[1032,9217,1573],{"class":1049},[1032,9219,9220,9222,9225,9227,9229,9231],{"class":1034,"line":1600},[1032,9221,1039],{"class":1038},[1032,9223,9224],{"class":1042}," visitorVacation",[1032,9226,1046],{"class":1038},[1032,9228,1530],{"class":1038},[1032,9230,9067],{"class":1195},[1032,9232,1573],{"class":1049},[1032,9234,9235],{"class":1034,"line":1615},[1032,9236,1087],{"emptyLinePlaceholder":1086},[1032,9238,9239,9241,9243,9245,9247,9249,9251,9253,9255,9258,9260,9262,9264,9266,9268],{"class":1034,"line":1631},[1032,9240,5356],{"class":1038},[1032,9242,5359],{"class":1049},[1032,9244,5362],{"class":1038},[1032,9246,5365],{"class":1049},[1032,9248,1226],{"class":1038},[1032,9250,3756],{"class":1042},[1032,9252,5372],{"class":1049},[1032,9254,1226],{"class":1038},[1032,9256,9257],{"class":1049}," employees.",[1032,9259,4719],{"class":1042},[1032,9261,5382],{"class":1049},[1032,9263,5385],{"class":1038},[1032,9265,5388],{"class":1049},[1032,9267,5391],{"class":1038},[1032,9269,1214],{"class":1049},[1032,9271,9272,9275,9278,9280],{"class":1034,"line":1642},[1032,9273,9274],{"class":1038},"  const",[1032,9276,9277],{"class":1042}," employee",[1032,9279,1046],{"class":1038},[1032,9281,9282],{"class":1049}," employees[i];\n",[1032,9284,9285],{"class":1034,"line":1648},[1032,9286,1087],{"emptyLinePlaceholder":1086},[1032,9288,9289,9292,9295],{"class":1034,"line":1653},[1032,9290,9291],{"class":1049},"  employee.",[1032,9293,9294],{"class":1195},"accept",[1032,9296,9297],{"class":1049},"(visitorSalary);\n",[1032,9299,9300,9302,9304],{"class":1034,"line":1669},[1032,9301,9291],{"class":1049},[1032,9303,9294],{"class":1195},[1032,9305,9306],{"class":1049},"(visitorVacation);\n",[1032,9308,9309],{"class":1034,"line":1682},[1032,9310,1087],{"emptyLinePlaceholder":1086},[1032,9312,9313,9315,9317],{"class":1034,"line":1695},[1032,9314,5824],{"class":1049},[1032,9316,1728],{"class":1195},[1032,9318,9319],{"class":1049},"(\n",[1032,9321,9322,9325,9327,9329,9331,9334,9337,9339,9341,9343,9345,9348],{"class":1034,"line":1705},[1032,9323,9324],{"class":1059},"    `emp.getName() earns $${",[1032,9326,9022],{"class":1049},[1032,9328,1271],{"class":1059},[1032,9330,9038],{"class":1195},[1032,9332,9333],{"class":1059},"()",[1032,9335,9336],{"class":1059},"} and gets ${",[1032,9338,9022],{"class":1049},[1032,9340,1271],{"class":1059},[1032,9342,9091],{"class":1195},[1032,9344,9333],{"class":1059},[1032,9346,9347],{"class":1059},"} vacation days`",[1032,9349,1063],{"class":1049},[1032,9351,9352],{"class":1034,"line":1710},[1032,9353,9354],{"class":1049},"  );\n",[1032,9356,9357],{"class":1034,"line":1715},[1032,9358,1312],{"class":1049},[953,9360,9362],{"id":9361},"structural-design-patterns","Structural Design Patterns",[994,9364,9366],{"id":9365},"adapter","Adapter",[927,9368,2741,9369,9373],{},[967,9370,9371],{},[930,9372,9366],{}," Pattern is a structural design pattern that allows the interface of an existing class to be used as another interface. It is often used to make existing classes work with others without modifying their source code.",[927,9375,9376],{},[948,9377],{"alt":9366,"src":9378},"\u002Fimages\u002Fblog\u002F2021-12-16-javascript-design-patterns\u002Fadapter.png",[927,9380,2138,9381,9385],{},[967,9382,9383],{},[930,9384,9366],{}," pattern translates one interface (an object‘s properties and methods) to another. Adapters allow programming components to work together that otherwise wouldn't because of mismatched interfaces. The Adapter pattern is also referred to as the Wrapper Pattern.",[1022,9387,9389],{"className":1024,"code":9388,"language":1026,"meta":1027,"style":1027},"\u002F\u002F old interface\nclass Shipping {\n  request(zipStart, zipEnd, weight) {\n    const baseCost = 24.38;\n    return baseCost * weight;\n  }\n}\n\n\u002F\u002F new interface\nclass AdvancedShipping {\n  login(credentials) {\n    this.credentials = credentials;\n  }\n\n  setStart(start) {\n    this.start = start;\n  }\n\n  setDestination(destination) {\n    this.destination = destination;\n  }\n\n  calculate(weight) {\n    const baseCost = 22.49;\n    return baseCost * weight;\n  }\n}\n\n\u002F\u002F adapter interface\nclass ShippingAdapter {\n  constructor(credentials) {\n    this.credentials = credentials;\n    const shipping = new AdvancedShipping();\n\n    shipping.login(credentials);\n\n    return {\n      request: function (zipStart, zipEnd, weight) {\n        shipping.setStart(zipStart);\n        shipping.setDestination(zipEnd);\n        return shipping.calculate(weight);\n      },\n    };\n  }\n}\n\nconst shipping = new Shipping();\nconst credentials = { token: '49ab1-7re8' };\nconst adapter = new ShippingAdapter(credentials);\n\n\u002F\u002F original shipping object and interface\nlet cost = shipping.request('89801', '10210', 2);\nconsole.log('Old cost: $' + cost);\n\n\u002F\u002F new shipping object with adapted interface\ncost = adapter.request('89801', '10210', 2);\n\nconsole.log('New cost: $' + cost);\n",[1029,9390,9391,9396,9404,9424,9438,9449,9453,9457,9461,9466,9475,9487,9499,9503,9507,9518,9530,9534,9538,9550,9562,9566,9570,9580,9593,9603,9607,9611,9615,9620,9629,9639,9649,9663,9667,9678,9682,9688,9712,9723,9733,9744,9749,9754,9758,9762,9766,9780,9797,9812,9816,9821,9850,9866,9870,9875,9901,9905],{"__ignoreMap":1027},[1032,9392,9393],{"class":1034,"line":1035},[1032,9394,9395],{"class":1718},"\u002F\u002F old interface\n",[1032,9397,9398,9400,9402],{"class":1034,"line":1053},[1032,9399,1192],{"class":1038},[1032,9401,7953],{"class":1195},[1032,9403,1050],{"class":1049},[1032,9405,9406,9408,9410,9413,9415,9418,9420,9422],{"class":1034,"line":1066},[1032,9407,3498],{"class":1195},[1032,9409,1207],{"class":1049},[1032,9411,9412],{"class":1210},"zipStart",[1032,9414,2819],{"class":1049},[1032,9416,9417],{"class":1210},"zipEnd",[1032,9419,2819],{"class":1049},[1032,9421,8072],{"class":1210},[1032,9423,1214],{"class":1049},[1032,9425,9426,9428,9431,9433,9436],{"class":1034,"line":1077},[1032,9427,3192],{"class":1038},[1032,9429,9430],{"class":1042}," baseCost",[1032,9432,1046],{"class":1038},[1032,9434,9435],{"class":1042}," 24.38",[1032,9437,1251],{"class":1049},[1032,9439,9440,9442,9445,9447],{"class":1034,"line":1083},[1032,9441,1527],{"class":1038},[1032,9443,9444],{"class":1049}," baseCost ",[1032,9446,3547],{"class":1038},[1032,9448,8106],{"class":1049},[1032,9450,9451],{"class":1034,"line":1090},[1032,9452,1306],{"class":1049},[1032,9454,9455],{"class":1034,"line":1102},[1032,9456,1312],{"class":1049},[1032,9458,9459],{"class":1034,"line":1113},[1032,9460,1087],{"emptyLinePlaceholder":1086},[1032,9462,9463],{"class":1034,"line":1124},[1032,9464,9465],{"class":1718},"\u002F\u002F new interface\n",[1032,9467,9468,9470,9473],{"class":1034,"line":1135},[1032,9469,1192],{"class":1038},[1032,9471,9472],{"class":1195}," AdvancedShipping",[1032,9474,1050],{"class":1049},[1032,9476,9477,9480,9482,9485],{"class":1034,"line":1140},[1032,9478,9479],{"class":1195},"  login",[1032,9481,1207],{"class":1049},[1032,9483,9484],{"class":1210},"credentials",[1032,9486,1214],{"class":1049},[1032,9488,9489,9491,9494,9496],{"class":1034,"line":1145},[1032,9490,1220],{"class":1042},[1032,9492,9493],{"class":1049},".credentials ",[1032,9495,1226],{"class":1038},[1032,9497,9498],{"class":1049}," credentials;\n",[1032,9500,9501],{"class":1034,"line":1157},[1032,9502,1306],{"class":1049},[1032,9504,9505],{"class":1034,"line":1168},[1032,9506,1087],{"emptyLinePlaceholder":1086},[1032,9508,9509,9512,9514,9516],{"class":1034,"line":1179},[1032,9510,9511],{"class":1195},"  setStart",[1032,9513,1207],{"class":1049},[1032,9515,7910],{"class":1210},[1032,9517,1214],{"class":1049},[1032,9519,9520,9522,9525,9527],{"class":1034,"line":1184},[1032,9521,1220],{"class":1042},[1032,9523,9524],{"class":1049},".start ",[1032,9526,1226],{"class":1038},[1032,9528,9529],{"class":1049}," start;\n",[1032,9531,9532],{"class":1034,"line":1189},[1032,9533,1306],{"class":1049},[1032,9535,9536],{"class":1034,"line":1201},[1032,9537,1087],{"emptyLinePlaceholder":1086},[1032,9539,9540,9543,9545,9548],{"class":1034,"line":1217},[1032,9541,9542],{"class":1195},"  setDestination",[1032,9544,1207],{"class":1049},[1032,9546,9547],{"class":1210},"destination",[1032,9549,1214],{"class":1049},[1032,9551,9552,9554,9557,9559],{"class":1034,"line":1232},[1032,9553,1220],{"class":1042},[1032,9555,9556],{"class":1049},".destination ",[1032,9558,1226],{"class":1038},[1032,9560,9561],{"class":1049}," destination;\n",[1032,9563,9564],{"class":1034,"line":1254},[1032,9565,1306],{"class":1049},[1032,9567,9568],{"class":1034,"line":1279},[1032,9569,1087],{"emptyLinePlaceholder":1086},[1032,9571,9572,9574,9576,9578],{"class":1034,"line":1303},[1032,9573,8019],{"class":1195},[1032,9575,1207],{"class":1049},[1032,9577,8072],{"class":1210},[1032,9579,1214],{"class":1049},[1032,9581,9582,9584,9586,9588,9591],{"class":1034,"line":1309},[1032,9583,3192],{"class":1038},[1032,9585,9430],{"class":1042},[1032,9587,1046],{"class":1038},[1032,9589,9590],{"class":1042}," 22.49",[1032,9592,1251],{"class":1049},[1032,9594,9595,9597,9599,9601],{"class":1034,"line":1315},[1032,9596,1527],{"class":1038},[1032,9598,9444],{"class":1049},[1032,9600,3547],{"class":1038},[1032,9602,8106],{"class":1049},[1032,9604,9605],{"class":1034,"line":1320},[1032,9606,1306],{"class":1049},[1032,9608,9609],{"class":1034,"line":1330},[1032,9610,1312],{"class":1049},[1032,9612,9613],{"class":1034,"line":1341},[1032,9614,1087],{"emptyLinePlaceholder":1086},[1032,9616,9617],{"class":1034,"line":1352},[1032,9618,9619],{"class":1718},"\u002F\u002F adapter interface\n",[1032,9621,9622,9624,9627],{"class":1034,"line":1374},[1032,9623,1192],{"class":1038},[1032,9625,9626],{"class":1195}," ShippingAdapter",[1032,9628,1050],{"class":1049},[1032,9630,9631,9633,9635,9637],{"class":1034,"line":1396},[1032,9632,1204],{"class":1038},[1032,9634,1207],{"class":1049},[1032,9636,9484],{"class":1210},[1032,9638,1214],{"class":1049},[1032,9640,9641,9643,9645,9647],{"class":1034,"line":1401},[1032,9642,1220],{"class":1042},[1032,9644,9493],{"class":1049},[1032,9646,1226],{"class":1038},[1032,9648,9498],{"class":1049},[1032,9650,9651,9653,9655,9657,9659,9661],{"class":1034,"line":1406},[1032,9652,3192],{"class":1038},[1032,9654,8354],{"class":1042},[1032,9656,1046],{"class":1038},[1032,9658,1530],{"class":1038},[1032,9660,9472],{"class":1195},[1032,9662,1573],{"class":1049},[1032,9664,9665],{"class":1034,"line":1411},[1032,9666,1087],{"emptyLinePlaceholder":1086},[1032,9668,9669,9672,9675],{"class":1034,"line":1421},[1032,9670,9671],{"class":1049},"    shipping.",[1032,9673,9674],{"class":1195},"login",[1032,9676,9677],{"class":1049},"(credentials);\n",[1032,9679,9680],{"class":1034,"line":1433},[1032,9681,1087],{"emptyLinePlaceholder":1086},[1032,9683,9684,9686],{"class":1034,"line":1442},[1032,9685,1527],{"class":1038},[1032,9687,1050],{"class":1049},[1032,9689,9690,9693,9696,9698,9700,9702,9704,9706,9708,9710],{"class":1034,"line":1458},[1032,9691,9692],{"class":1195},"      request",[1032,9694,9695],{"class":1049},": ",[1032,9697,5812],{"class":1038},[1032,9699,5359],{"class":1049},[1032,9701,9412],{"class":1210},[1032,9703,2819],{"class":1049},[1032,9705,9417],{"class":1210},[1032,9707,2819],{"class":1049},[1032,9709,8072],{"class":1210},[1032,9711,1214],{"class":1049},[1032,9713,9714,9717,9720],{"class":1034,"line":1472},[1032,9715,9716],{"class":1049},"        shipping.",[1032,9718,9719],{"class":1195},"setStart",[1032,9721,9722],{"class":1049},"(zipStart);\n",[1032,9724,9725,9727,9730],{"class":1034,"line":1480},[1032,9726,9716],{"class":1049},[1032,9728,9729],{"class":1195},"setDestination",[1032,9731,9732],{"class":1049},"(zipEnd);\n",[1032,9734,9735,9737,9739,9741],{"class":1034,"line":1494},[1032,9736,7190],{"class":1038},[1032,9738,8393],{"class":1049},[1032,9740,8038],{"class":1195},[1032,9742,9743],{"class":1049},"(weight);\n",[1032,9745,9746],{"class":1034,"line":1506},[1032,9747,9748],{"class":1049},"      },\n",[1032,9750,9751],{"class":1034,"line":1513},[1032,9752,9753],{"class":1049},"    };\n",[1032,9755,9756],{"class":1034,"line":1519},[1032,9757,1306],{"class":1049},[1032,9759,9760],{"class":1034,"line":1524},[1032,9761,1312],{"class":1049},[1032,9763,9764],{"class":1034,"line":1544},[1032,9765,1087],{"emptyLinePlaceholder":1086},[1032,9767,9768,9770,9772,9774,9776,9778],{"class":1034,"line":1549},[1032,9769,1039],{"class":1038},[1032,9771,8354],{"class":1042},[1032,9773,1046],{"class":1038},[1032,9775,1530],{"class":1038},[1032,9777,7953],{"class":1195},[1032,9779,1573],{"class":1049},[1032,9781,9782,9784,9787,9789,9792,9795],{"class":1034,"line":1554},[1032,9783,1039],{"class":1038},[1032,9785,9786],{"class":1042}," credentials",[1032,9788,1046],{"class":1038},[1032,9790,9791],{"class":1049}," { token: ",[1032,9793,9794],{"class":1059},"'49ab1-7re8'",[1032,9796,8294],{"class":1049},[1032,9798,9799,9801,9804,9806,9808,9810],{"class":1034,"line":1559},[1032,9800,1039],{"class":1038},[1032,9802,9803],{"class":1042}," adapter",[1032,9805,1046],{"class":1038},[1032,9807,1530],{"class":1038},[1032,9809,9626],{"class":1195},[1032,9811,9677],{"class":1049},[1032,9813,9814],{"class":1034,"line":1576},[1032,9815,1087],{"emptyLinePlaceholder":1086},[1032,9817,9818],{"class":1034,"line":1581},[1032,9819,9820],{"class":1718},"\u002F\u002F original shipping object and interface\n",[1032,9822,9823,9825,9828,9830,9832,9834,9836,9839,9841,9844,9846,9848],{"class":1034,"line":1600},[1032,9824,5362],{"class":1038},[1032,9826,9827],{"class":1049}," cost ",[1032,9829,1226],{"class":1038},[1032,9831,8393],{"class":1049},[1032,9833,3630],{"class":1195},[1032,9835,1207],{"class":1049},[1032,9837,9838],{"class":1059},"'89801'",[1032,9840,2819],{"class":1049},[1032,9842,9843],{"class":1059},"'10210'",[1032,9845,2819],{"class":1049},[1032,9847,4527],{"class":1042},[1032,9849,1743],{"class":1049},[1032,9851,9852,9854,9856,9858,9861,9863],{"class":1034,"line":1615},[1032,9853,1725],{"class":1049},[1032,9855,1728],{"class":1195},[1032,9857,1207],{"class":1049},[1032,9859,9860],{"class":1059},"'Old cost: $'",[1032,9862,5429],{"class":1038},[1032,9864,9865],{"class":1049}," cost);\n",[1032,9867,9868],{"class":1034,"line":1631},[1032,9869,1087],{"emptyLinePlaceholder":1086},[1032,9871,9872],{"class":1034,"line":1642},[1032,9873,9874],{"class":1718},"\u002F\u002F new shipping object with adapted interface\n",[1032,9876,9877,9880,9882,9885,9887,9889,9891,9893,9895,9897,9899],{"class":1034,"line":1648},[1032,9878,9879],{"class":1049},"cost ",[1032,9881,1226],{"class":1038},[1032,9883,9884],{"class":1049}," adapter.",[1032,9886,3630],{"class":1195},[1032,9888,1207],{"class":1049},[1032,9890,9838],{"class":1059},[1032,9892,2819],{"class":1049},[1032,9894,9843],{"class":1059},[1032,9896,2819],{"class":1049},[1032,9898,4527],{"class":1042},[1032,9900,1743],{"class":1049},[1032,9902,9903],{"class":1034,"line":1653},[1032,9904,1087],{"emptyLinePlaceholder":1086},[1032,9906,9907,9909,9911,9913,9916,9918],{"class":1034,"line":1669},[1032,9908,1725],{"class":1049},[1032,9910,1728],{"class":1195},[1032,9912,1207],{"class":1049},[1032,9914,9915],{"class":1059},"'New cost: $'",[1032,9917,5429],{"class":1038},[1032,9919,9865],{"class":1049},[927,9921,9922,9923,9926],{},"The example code above shows an online shopping cart in which a shipping object is used to compute shipping costs. The old ",[1029,9924,9925],{},"Shipping"," object is replaced by a new and improved Shipping object that is more secure and offers better prices.",[927,9928,9929,9930,9933,9934,9937,9938,9940,9941,9943],{},"The new object is named ",[1029,9931,9932],{},"AdvancedShipping"," and has a very different interface which the client program does not expect. ",[1029,9935,9936],{},"ShippingAdapter"," allows the client program to continue functioning without any API changes by mapping (adapting) the old ",[1029,9939,9925],{}," interface to the new ",[1029,9942,9932],{}," interface.",[994,9945,9947],{"id":9946},"bridge","Bridge",[927,9949,9950,9951,9956],{},"Bridge is a ",[967,9952,9953],{},[930,9954,9955],{},"Structural"," design pattern that lets you split a large class or a set of closely related classes into two separate hierarchies — abstraction and implementation — which can be developed independently of each other.",[927,9958,9959],{},[948,9960],{"alt":9947,"src":9961},"\u002Fimages\u002Fblog\u002F2021-12-16-javascript-design-patterns\u002Fbridge.png",[927,9963,2138,9964,9968],{},[967,9965,9966],{},[930,9967,9947],{}," pattern allows two components, a client and a service, to work together with each component having its own interface. Bridge is a high-level architectural pattern and its main goal is to write better code through two levels of abstraction. It facilitates the very loose coupling of objects. It is sometimes referred to as a double Adapter pattern.",[1022,9970,9972],{"className":1024,"code":9971,"language":1026,"meta":1027,"style":1027},"\u002F\u002F input devices\nclass Gestures {\n  constructor(output) {\n    this.output = output;\n  }\n\n  tap() {\n    this.output.click();\n  }\n\n  swipe() {\n    this.output.move();\n  }\n\n  pan() {\n    this.output.drag();\n  }\n\n  pinch() {\n    this.output.zoom();\n  }\n}\n\nclass Mouse {\n  constructor(output) {\n    this.output = output;\n  }\n\n  click() {\n    this.output.click();\n  }\n\n  move() {\n    this.output.move();\n  }\n\n  down() {\n    this.output.drag();\n  }\n\n  wheel() {\n    this.output.zoom();\n  }\n}\n\n\u002F\u002F output devices\nclass Screen {\n  click() {\n    console.log('Screen select');\n  }\n\n  move() {\n    console.log('Screen move');\n  }\n\n  drag() {\n    console.log('Screen drag');\n  }\n\n  zoom() {\n    console.log('Screen zoom in');\n  }\n}\n\nclass Audio {\n  click() {\n    console.log('Sound oink');\n  }\n\n  move() {\n    console.log('Sound waves');\n  }\n\n  drag() {\n    console.log('Sound screetch');\n  }\n\n  zoom() {\n    console.log('Sound volume up');\n  }\n}\n\nconst screen = new Screen();\nconst audio = new Audio();\n\nconst hand = new Gestures(screen);\nconst mouse = new Mouse(audio);\n\nhand.tap();\nhand.swipe();\nhand.pinch();\n\nmouse.click();\nmouse.move();\nmouse.wheel();\n",[1029,9973,9974,9979,9988,9999,10010,10014,10018,10025,10037,10041,10045,10052,10063,10067,10071,10078,10089,10093,10097,10104,10115,10119,10123,10127,10136,10146,10156,10160,10164,10171,10181,10185,10189,10196,10206,10210,10214,10221,10231,10235,10239,10246,10256,10260,10264,10268,10273,10282,10288,10301,10305,10309,10315,10328,10332,10336,10343,10356,10360,10364,10371,10384,10388,10392,10396,10405,10411,10424,10428,10432,10438,10451,10455,10459,10465,10478,10482,10486,10492,10505,10509,10513,10517,10532,10547,10551,10567,10583,10587,10597,10606,10615,10619,10628,10636],{"__ignoreMap":1027},[1032,9975,9976],{"class":1034,"line":1035},[1032,9977,9978],{"class":1718},"\u002F\u002F input devices\n",[1032,9980,9981,9983,9986],{"class":1034,"line":1053},[1032,9982,1192],{"class":1038},[1032,9984,9985],{"class":1195}," Gestures",[1032,9987,1050],{"class":1049},[1032,9989,9990,9992,9994,9997],{"class":1034,"line":1066},[1032,9991,1204],{"class":1038},[1032,9993,1207],{"class":1049},[1032,9995,9996],{"class":1210},"output",[1032,9998,1214],{"class":1049},[1032,10000,10001,10003,10005,10007],{"class":1034,"line":1077},[1032,10002,1220],{"class":1042},[1032,10004,4670],{"class":1049},[1032,10006,1226],{"class":1038},[1032,10008,10009],{"class":1049}," output;\n",[1032,10011,10012],{"class":1034,"line":1083},[1032,10013,1306],{"class":1049},[1032,10015,10016],{"class":1034,"line":1090},[1032,10017,1087],{"emptyLinePlaceholder":1086},[1032,10019,10020,10023],{"class":1034,"line":1102},[1032,10021,10022],{"class":1195},"  tap",[1032,10024,1868],{"class":1049},[1032,10026,10027,10029,10032,10035],{"class":1034,"line":1113},[1032,10028,1220],{"class":1042},[1032,10030,10031],{"class":1049},".output.",[1032,10033,10034],{"class":1195},"click",[1032,10036,1573],{"class":1049},[1032,10038,10039],{"class":1034,"line":1124},[1032,10040,1306],{"class":1049},[1032,10042,10043],{"class":1034,"line":1135},[1032,10044,1087],{"emptyLinePlaceholder":1086},[1032,10046,10047,10050],{"class":1034,"line":1140},[1032,10048,10049],{"class":1195},"  swipe",[1032,10051,1868],{"class":1049},[1032,10053,10054,10056,10058,10061],{"class":1034,"line":1145},[1032,10055,1220],{"class":1042},[1032,10057,10031],{"class":1049},[1032,10059,10060],{"class":1195},"move",[1032,10062,1573],{"class":1049},[1032,10064,10065],{"class":1034,"line":1157},[1032,10066,1306],{"class":1049},[1032,10068,10069],{"class":1034,"line":1168},[1032,10070,1087],{"emptyLinePlaceholder":1086},[1032,10072,10073,10076],{"class":1034,"line":1179},[1032,10074,10075],{"class":1195},"  pan",[1032,10077,1868],{"class":1049},[1032,10079,10080,10082,10084,10087],{"class":1034,"line":1184},[1032,10081,1220],{"class":1042},[1032,10083,10031],{"class":1049},[1032,10085,10086],{"class":1195},"drag",[1032,10088,1573],{"class":1049},[1032,10090,10091],{"class":1034,"line":1189},[1032,10092,1306],{"class":1049},[1032,10094,10095],{"class":1034,"line":1201},[1032,10096,1087],{"emptyLinePlaceholder":1086},[1032,10098,10099,10102],{"class":1034,"line":1217},[1032,10100,10101],{"class":1195},"  pinch",[1032,10103,1868],{"class":1049},[1032,10105,10106,10108,10110,10113],{"class":1034,"line":1232},[1032,10107,1220],{"class":1042},[1032,10109,10031],{"class":1049},[1032,10111,10112],{"class":1195},"zoom",[1032,10114,1573],{"class":1049},[1032,10116,10117],{"class":1034,"line":1254},[1032,10118,1306],{"class":1049},[1032,10120,10121],{"class":1034,"line":1279},[1032,10122,1312],{"class":1049},[1032,10124,10125],{"class":1034,"line":1303},[1032,10126,1087],{"emptyLinePlaceholder":1086},[1032,10128,10129,10131,10134],{"class":1034,"line":1309},[1032,10130,1192],{"class":1038},[1032,10132,10133],{"class":1195}," Mouse",[1032,10135,1050],{"class":1049},[1032,10137,10138,10140,10142,10144],{"class":1034,"line":1315},[1032,10139,1204],{"class":1038},[1032,10141,1207],{"class":1049},[1032,10143,9996],{"class":1210},[1032,10145,1214],{"class":1049},[1032,10147,10148,10150,10152,10154],{"class":1034,"line":1320},[1032,10149,1220],{"class":1042},[1032,10151,4670],{"class":1049},[1032,10153,1226],{"class":1038},[1032,10155,10009],{"class":1049},[1032,10157,10158],{"class":1034,"line":1330},[1032,10159,1306],{"class":1049},[1032,10161,10162],{"class":1034,"line":1341},[1032,10163,1087],{"emptyLinePlaceholder":1086},[1032,10165,10166,10169],{"class":1034,"line":1352},[1032,10167,10168],{"class":1195},"  click",[1032,10170,1868],{"class":1049},[1032,10172,10173,10175,10177,10179],{"class":1034,"line":1374},[1032,10174,1220],{"class":1042},[1032,10176,10031],{"class":1049},[1032,10178,10034],{"class":1195},[1032,10180,1573],{"class":1049},[1032,10182,10183],{"class":1034,"line":1396},[1032,10184,1306],{"class":1049},[1032,10186,10187],{"class":1034,"line":1401},[1032,10188,1087],{"emptyLinePlaceholder":1086},[1032,10190,10191,10194],{"class":1034,"line":1406},[1032,10192,10193],{"class":1195},"  move",[1032,10195,1868],{"class":1049},[1032,10197,10198,10200,10202,10204],{"class":1034,"line":1411},[1032,10199,1220],{"class":1042},[1032,10201,10031],{"class":1049},[1032,10203,10060],{"class":1195},[1032,10205,1573],{"class":1049},[1032,10207,10208],{"class":1034,"line":1421},[1032,10209,1306],{"class":1049},[1032,10211,10212],{"class":1034,"line":1433},[1032,10213,1087],{"emptyLinePlaceholder":1086},[1032,10215,10216,10219],{"class":1034,"line":1442},[1032,10217,10218],{"class":1195},"  down",[1032,10220,1868],{"class":1049},[1032,10222,10223,10225,10227,10229],{"class":1034,"line":1458},[1032,10224,1220],{"class":1042},[1032,10226,10031],{"class":1049},[1032,10228,10086],{"class":1195},[1032,10230,1573],{"class":1049},[1032,10232,10233],{"class":1034,"line":1472},[1032,10234,1306],{"class":1049},[1032,10236,10237],{"class":1034,"line":1480},[1032,10238,1087],{"emptyLinePlaceholder":1086},[1032,10240,10241,10244],{"class":1034,"line":1494},[1032,10242,10243],{"class":1195},"  wheel",[1032,10245,1868],{"class":1049},[1032,10247,10248,10250,10252,10254],{"class":1034,"line":1506},[1032,10249,1220],{"class":1042},[1032,10251,10031],{"class":1049},[1032,10253,10112],{"class":1195},[1032,10255,1573],{"class":1049},[1032,10257,10258],{"class":1034,"line":1513},[1032,10259,1306],{"class":1049},[1032,10261,10262],{"class":1034,"line":1519},[1032,10263,1312],{"class":1049},[1032,10265,10266],{"class":1034,"line":1524},[1032,10267,1087],{"emptyLinePlaceholder":1086},[1032,10269,10270],{"class":1034,"line":1544},[1032,10271,10272],{"class":1718},"\u002F\u002F output devices\n",[1032,10274,10275,10277,10280],{"class":1034,"line":1549},[1032,10276,1192],{"class":1038},[1032,10278,10279],{"class":1195}," Screen",[1032,10281,1050],{"class":1049},[1032,10283,10284,10286],{"class":1034,"line":1554},[1032,10285,10168],{"class":1195},[1032,10287,1868],{"class":1049},[1032,10289,10290,10292,10294,10296,10299],{"class":1034,"line":1559},[1032,10291,1873],{"class":1049},[1032,10293,1728],{"class":1195},[1032,10295,1207],{"class":1049},[1032,10297,10298],{"class":1059},"'Screen select'",[1032,10300,1743],{"class":1049},[1032,10302,10303],{"class":1034,"line":1576},[1032,10304,1306],{"class":1049},[1032,10306,10307],{"class":1034,"line":1581},[1032,10308,1087],{"emptyLinePlaceholder":1086},[1032,10310,10311,10313],{"class":1034,"line":1600},[1032,10312,10193],{"class":1195},[1032,10314,1868],{"class":1049},[1032,10316,10317,10319,10321,10323,10326],{"class":1034,"line":1615},[1032,10318,1873],{"class":1049},[1032,10320,1728],{"class":1195},[1032,10322,1207],{"class":1049},[1032,10324,10325],{"class":1059},"'Screen move'",[1032,10327,1743],{"class":1049},[1032,10329,10330],{"class":1034,"line":1631},[1032,10331,1306],{"class":1049},[1032,10333,10334],{"class":1034,"line":1642},[1032,10335,1087],{"emptyLinePlaceholder":1086},[1032,10337,10338,10341],{"class":1034,"line":1648},[1032,10339,10340],{"class":1195},"  drag",[1032,10342,1868],{"class":1049},[1032,10344,10345,10347,10349,10351,10354],{"class":1034,"line":1653},[1032,10346,1873],{"class":1049},[1032,10348,1728],{"class":1195},[1032,10350,1207],{"class":1049},[1032,10352,10353],{"class":1059},"'Screen drag'",[1032,10355,1743],{"class":1049},[1032,10357,10358],{"class":1034,"line":1669},[1032,10359,1306],{"class":1049},[1032,10361,10362],{"class":1034,"line":1682},[1032,10363,1087],{"emptyLinePlaceholder":1086},[1032,10365,10366,10369],{"class":1034,"line":1695},[1032,10367,10368],{"class":1195},"  zoom",[1032,10370,1868],{"class":1049},[1032,10372,10373,10375,10377,10379,10382],{"class":1034,"line":1705},[1032,10374,1873],{"class":1049},[1032,10376,1728],{"class":1195},[1032,10378,1207],{"class":1049},[1032,10380,10381],{"class":1059},"'Screen zoom in'",[1032,10383,1743],{"class":1049},[1032,10385,10386],{"class":1034,"line":1710},[1032,10387,1306],{"class":1049},[1032,10389,10390],{"class":1034,"line":1715},[1032,10391,1312],{"class":1049},[1032,10393,10394],{"class":1034,"line":1722},[1032,10395,1087],{"emptyLinePlaceholder":1086},[1032,10397,10398,10400,10403],{"class":1034,"line":1746},[1032,10399,1192],{"class":1038},[1032,10401,10402],{"class":1195}," Audio",[1032,10404,1050],{"class":1049},[1032,10406,10407,10409],{"class":1034,"line":1752},[1032,10408,10168],{"class":1195},[1032,10410,1868],{"class":1049},[1032,10412,10413,10415,10417,10419,10422],{"class":1034,"line":1762},[1032,10414,1873],{"class":1049},[1032,10416,1728],{"class":1195},[1032,10418,1207],{"class":1049},[1032,10420,10421],{"class":1059},"'Sound oink'",[1032,10423,1743],{"class":1049},[1032,10425,10426],{"class":1034,"line":1767},[1032,10427,1306],{"class":1049},[1032,10429,10430],{"class":1034,"line":1787},[1032,10431,1087],{"emptyLinePlaceholder":1086},[1032,10433,10434,10436],{"class":1034,"line":1793},[1032,10435,10193],{"class":1195},[1032,10437,1868],{"class":1049},[1032,10439,10440,10442,10444,10446,10449],{"class":1034,"line":4312},[1032,10441,1873],{"class":1049},[1032,10443,1728],{"class":1195},[1032,10445,1207],{"class":1049},[1032,10447,10448],{"class":1059},"'Sound waves'",[1032,10450,1743],{"class":1049},[1032,10452,10453],{"class":1034,"line":4323},[1032,10454,1306],{"class":1049},[1032,10456,10457],{"class":1034,"line":4336},[1032,10458,1087],{"emptyLinePlaceholder":1086},[1032,10460,10461,10463],{"class":1034,"line":4341},[1032,10462,10340],{"class":1195},[1032,10464,1868],{"class":1049},[1032,10466,10467,10469,10471,10473,10476],{"class":1034,"line":4346},[1032,10468,1873],{"class":1049},[1032,10470,1728],{"class":1195},[1032,10472,1207],{"class":1049},[1032,10474,10475],{"class":1059},"'Sound screetch'",[1032,10477,1743],{"class":1049},[1032,10479,10480],{"class":1034,"line":4351},[1032,10481,1306],{"class":1049},[1032,10483,10484],{"class":1034,"line":4361},[1032,10485,1087],{"emptyLinePlaceholder":1086},[1032,10487,10488,10490],{"class":1034,"line":4372},[1032,10489,10368],{"class":1195},[1032,10491,1868],{"class":1049},[1032,10493,10494,10496,10498,10500,10503],{"class":1034,"line":4384},[1032,10495,1873],{"class":1049},[1032,10497,1728],{"class":1195},[1032,10499,1207],{"class":1049},[1032,10501,10502],{"class":1059},"'Sound volume up'",[1032,10504,1743],{"class":1049},[1032,10506,10507],{"class":1034,"line":4389},[1032,10508,1306],{"class":1049},[1032,10510,10511],{"class":1034,"line":4394},[1032,10512,1312],{"class":1049},[1032,10514,10515],{"class":1034,"line":4405},[1032,10516,1087],{"emptyLinePlaceholder":1086},[1032,10518,10519,10521,10524,10526,10528,10530],{"class":1034,"line":4419},[1032,10520,1039],{"class":1038},[1032,10522,10523],{"class":1042}," screen",[1032,10525,1046],{"class":1038},[1032,10527,1530],{"class":1038},[1032,10529,10279],{"class":1195},[1032,10531,1573],{"class":1049},[1032,10533,10534,10536,10539,10541,10543,10545],{"class":1034,"line":4424},[1032,10535,1039],{"class":1038},[1032,10537,10538],{"class":1042}," audio",[1032,10540,1046],{"class":1038},[1032,10542,1530],{"class":1038},[1032,10544,10402],{"class":1195},[1032,10546,1573],{"class":1049},[1032,10548,10549],{"class":1034,"line":4429},[1032,10550,1087],{"emptyLinePlaceholder":1086},[1032,10552,10553,10555,10558,10560,10562,10564],{"class":1034,"line":4440},[1032,10554,1039],{"class":1038},[1032,10556,10557],{"class":1042}," hand",[1032,10559,1046],{"class":1038},[1032,10561,1530],{"class":1038},[1032,10563,9985],{"class":1195},[1032,10565,10566],{"class":1049},"(screen);\n",[1032,10568,10569,10571,10574,10576,10578,10580],{"class":1034,"line":4453},[1032,10570,1039],{"class":1038},[1032,10572,10573],{"class":1042}," mouse",[1032,10575,1046],{"class":1038},[1032,10577,1530],{"class":1038},[1032,10579,10133],{"class":1195},[1032,10581,10582],{"class":1049},"(audio);\n",[1032,10584,10585],{"class":1034,"line":4458},[1032,10586,1087],{"emptyLinePlaceholder":1086},[1032,10588,10589,10592,10595],{"class":1034,"line":4463},[1032,10590,10591],{"class":1049},"hand.",[1032,10593,10594],{"class":1195},"tap",[1032,10596,1573],{"class":1049},[1032,10598,10599,10601,10604],{"class":1034,"line":4468},[1032,10600,10591],{"class":1049},[1032,10602,10603],{"class":1195},"swipe",[1032,10605,1573],{"class":1049},[1032,10607,10608,10610,10613],{"class":1034,"line":4484},[1032,10609,10591],{"class":1049},[1032,10611,10612],{"class":1195},"pinch",[1032,10614,1573],{"class":1049},[1032,10616,10617],{"class":1034,"line":4489},[1032,10618,1087],{"emptyLinePlaceholder":1086},[1032,10620,10621,10624,10626],{"class":1034,"line":4512},[1032,10622,10623],{"class":1049},"mouse.",[1032,10625,10034],{"class":1195},[1032,10627,1573],{"class":1049},[1032,10629,10630,10632,10634],{"class":1034,"line":4532},[1032,10631,10623],{"class":1049},[1032,10633,10060],{"class":1195},[1032,10635,1573],{"class":1049},[1032,10637,10638,10640,10643],{"class":1034,"line":4551},[1032,10639,10623],{"class":1049},[1032,10641,10642],{"class":1195},"wheel",[1032,10644,1573],{"class":1049},[927,10646,10647],{},"The objective of the example is to show that with the Bridge pattern input and output devices can vary independently (without changes to the code); the devices are loosely coupled by two levels of abstraction.",[927,10649,10650,10653,10654,10657,10658,7468,10661,10664],{},[1029,10651,10652],{},"Gestures"," (finger movements) and the ",[1029,10655,10656],{},"Mouse"," are very different input devices, but their actions map to a common set of output instructions: click, move, drag, etc. ",[1029,10659,10660],{},"Screen",[1029,10662,10663],{},"Audio"," are very different output devices, but they respond to the same set of instructions. Of course, the effects are totally different, that is, video updates vs. sound effects. The Bridge pattern allows any input device to work with any output device.",[994,10666,10668],{"id":10667},"composite","Composite",[927,10670,10671],{},"The composite pattern describes a group of objects that are treated the same way as a single instance of the same type of object.",[927,10673,10674],{},[948,10675],{"alt":10668,"src":10676},"\u002Fimages\u002Fblog\u002F2021-12-16-javascript-design-patterns\u002Fcomposite.png",[927,10678,2138,10679,10683],{},[967,10680,10681],{},[930,10682,10668],{}," pattern allows the creation of objects with properties that are primitive items or a collection of objects. Each item in the collection can hold other collections themselves, creating deeply nested structures.",[1022,10685,10687],{"className":1024,"code":10686,"language":1026,"meta":1027,"style":1027},"class Node {\n  constructor(name) {\n    this.children = [];\n    this.name = name;\n  }\n\n  add(child) {\n    this.children.push(child);\n  }\n\n  remove(child) {\n    const length = this.children.length;\n    for (let i = 0; i \u003C length; i++) {\n      if (this.children[i] === child) {\n        this.children.splice(i, 1);\n        return;\n      }\n    }\n  }\n\n  getChild(i) {\n    return this.children[i];\n  }\n\n  hasChildren() {\n    return this.children.length > 0;\n  }\n}\n\n\u002F\u002F recursively traverse a (sub)tree\nfunction traverse(indent, node) {\n  console.log(Array(indent++).join('--') + node.name);\n\n  for (let i = 0, len = node.children.length; i \u003C len; i++) {\n    traverse(indent, node.getChild(i));\n  }\n}\n\nconst tree = new Node('root');\nconst left = new Node('left');\nconst right = new Node('right');\nconst leftLeft = new Node('leftLeft');\nconst leftRight = new Node('leftRight');\nconst rightLeft = new Node('rightLeft');\nconst rightRight = new Node('rightRight');\n\ntree.add(left);\ntree.add(right);\ntree.remove(right);\ntree.add(right);\n\nleft.add(leftLeft);\nleft.add(leftRight);\n\nright.add(rightLeft);\nright.add(rightRight);\n\ntraverse(1, tree);\n",[1029,10688,10689,10698,10708,10719,10729,10733,10737,10748,10760,10764,10768,10779,10796,10821,10837,10853,10859,10863,10867,10871,10875,10887,10896,10900,10904,10911,10928,10932,10936,10940,10945,10964,10996,11000,11034,11048,11052,11056,11060,11079,11099,11119,11139,11159,11179,11199,11203,11212,11221,11230,11238,11242,11252,11261,11265,11275,11284,11288],{"__ignoreMap":1027},[1032,10690,10691,10693,10696],{"class":1034,"line":1035},[1032,10692,1192],{"class":1038},[1032,10694,10695],{"class":1195}," Node",[1032,10697,1050],{"class":1049},[1032,10699,10700,10702,10704,10706],{"class":1034,"line":1053},[1032,10701,1204],{"class":1038},[1032,10703,1207],{"class":1049},[1032,10705,4757],{"class":1210},[1032,10707,1214],{"class":1049},[1032,10709,10710,10712,10715,10717],{"class":1034,"line":1066},[1032,10711,1220],{"class":1042},[1032,10713,10714],{"class":1049},".children ",[1032,10716,1226],{"class":1038},[1032,10718,3770],{"class":1049},[1032,10720,10721,10723,10725,10727],{"class":1034,"line":1077},[1032,10722,1220],{"class":1042},[1032,10724,4791],{"class":1049},[1032,10726,1226],{"class":1038},[1032,10728,4796],{"class":1049},[1032,10730,10731],{"class":1034,"line":1083},[1032,10732,1306],{"class":1049},[1032,10734,10735],{"class":1034,"line":1090},[1032,10736,1087],{"emptyLinePlaceholder":1086},[1032,10738,10739,10741,10743,10746],{"class":1034,"line":1102},[1032,10740,3888],{"class":1195},[1032,10742,1207],{"class":1049},[1032,10744,10745],{"class":1210},"child",[1032,10747,1214],{"class":1049},[1032,10749,10750,10752,10755,10757],{"class":1034,"line":1113},[1032,10751,1220],{"class":1042},[1032,10753,10754],{"class":1049},".children.",[1032,10756,3820],{"class":1195},[1032,10758,10759],{"class":1049},"(child);\n",[1032,10761,10762],{"class":1034,"line":1124},[1032,10763,1306],{"class":1049},[1032,10765,10766],{"class":1034,"line":1135},[1032,10767,1087],{"emptyLinePlaceholder":1086},[1032,10769,10770,10773,10775,10777],{"class":1034,"line":1140},[1032,10771,10772],{"class":1195},"  remove",[1032,10774,1207],{"class":1049},[1032,10776,10745],{"class":1210},[1032,10778,1214],{"class":1049},[1032,10780,10781,10783,10786,10788,10790,10792,10794],{"class":1034,"line":1145},[1032,10782,3192],{"class":1038},[1032,10784,10785],{"class":1042}," length",[1032,10787,1046],{"class":1038},[1032,10789,1533],{"class":1042},[1032,10791,10754],{"class":1049},[1032,10793,4719],{"class":1042},[1032,10795,1251],{"class":1049},[1032,10797,10798,10800,10802,10804,10806,10808,10810,10812,10814,10817,10819],{"class":1034,"line":1157},[1032,10799,5687],{"class":1038},[1032,10801,5359],{"class":1049},[1032,10803,5362],{"class":1038},[1032,10805,5365],{"class":1049},[1032,10807,1226],{"class":1038},[1032,10809,3756],{"class":1042},[1032,10811,5382],{"class":1049},[1032,10813,5385],{"class":1038},[1032,10815,10816],{"class":1049}," length; i",[1032,10818,5391],{"class":1038},[1032,10820,1214],{"class":1049},[1032,10822,10823,10825,10827,10829,10832,10834],{"class":1034,"line":1168},[1032,10824,7177],{"class":1038},[1032,10826,5359],{"class":1049},[1032,10828,2298],{"class":1042},[1032,10830,10831],{"class":1049},".children[i] ",[1032,10833,1734],{"class":1038},[1032,10835,10836],{"class":1049}," child) {\n",[1032,10838,10839,10841,10843,10846,10849,10851],{"class":1034,"line":1179},[1032,10840,1461],{"class":1042},[1032,10842,10754],{"class":1049},[1032,10844,10845],{"class":1195},"splice",[1032,10847,10848],{"class":1049},"(i, ",[1032,10850,5057],{"class":1042},[1032,10852,1743],{"class":1049},[1032,10854,10855,10857],{"class":1034,"line":1184},[1032,10856,7190],{"class":1038},[1032,10858,1251],{"class":1049},[1032,10860,10861],{"class":1034,"line":1189},[1032,10862,6230],{"class":1049},[1032,10864,10865],{"class":1034,"line":1201},[1032,10866,1516],{"class":1049},[1032,10868,10869],{"class":1034,"line":1217},[1032,10870,1306],{"class":1049},[1032,10872,10873],{"class":1034,"line":1232},[1032,10874,1087],{"emptyLinePlaceholder":1086},[1032,10876,10877,10880,10882,10885],{"class":1034,"line":1254},[1032,10878,10879],{"class":1195},"  getChild",[1032,10881,1207],{"class":1049},[1032,10883,10884],{"class":1210},"i",[1032,10886,1214],{"class":1049},[1032,10888,10889,10891,10893],{"class":1034,"line":1279},[1032,10890,1527],{"class":1038},[1032,10892,1533],{"class":1042},[1032,10894,10895],{"class":1049},".children[i];\n",[1032,10897,10898],{"class":1034,"line":1303},[1032,10899,1306],{"class":1049},[1032,10901,10902],{"class":1034,"line":1309},[1032,10903,1087],{"emptyLinePlaceholder":1086},[1032,10905,10906,10909],{"class":1034,"line":1315},[1032,10907,10908],{"class":1195},"  hasChildren",[1032,10910,1868],{"class":1049},[1032,10912,10913,10915,10917,10919,10921,10924,10926],{"class":1034,"line":1320},[1032,10914,1527],{"class":1038},[1032,10916,1533],{"class":1042},[1032,10918,10754],{"class":1049},[1032,10920,4719],{"class":1042},[1032,10922,10923],{"class":1038}," >",[1032,10925,3756],{"class":1042},[1032,10927,1251],{"class":1049},[1032,10929,10930],{"class":1034,"line":1330},[1032,10931,1306],{"class":1049},[1032,10933,10934],{"class":1034,"line":1341},[1032,10935,1312],{"class":1049},[1032,10937,10938],{"class":1034,"line":1352},[1032,10939,1087],{"emptyLinePlaceholder":1086},[1032,10941,10942],{"class":1034,"line":1374},[1032,10943,10944],{"class":1718},"\u002F\u002F recursively traverse a (sub)tree\n",[1032,10946,10947,10949,10952,10954,10957,10959,10962],{"class":1034,"line":1396},[1032,10948,5812],{"class":1038},[1032,10950,10951],{"class":1195}," traverse",[1032,10953,1207],{"class":1049},[1032,10955,10956],{"class":1210},"indent",[1032,10958,2819],{"class":1049},[1032,10960,10961],{"class":1210},"node",[1032,10963,1214],{"class":1049},[1032,10965,10966,10968,10970,10972,10975,10978,10980,10982,10984,10986,10989,10991,10993],{"class":1034,"line":1401},[1032,10967,5824],{"class":1049},[1032,10969,1728],{"class":1195},[1032,10971,1207],{"class":1049},[1032,10973,10974],{"class":1195},"Array",[1032,10976,10977],{"class":1049},"(indent",[1032,10979,5391],{"class":1038},[1032,10981,3638],{"class":1049},[1032,10983,6353],{"class":1195},[1032,10985,1207],{"class":1049},[1032,10987,10988],{"class":1059},"'--'",[1032,10990,4722],{"class":1049},[1032,10992,3910],{"class":1038},[1032,10994,10995],{"class":1049}," node.name);\n",[1032,10997,10998],{"class":1034,"line":1406},[1032,10999,1087],{"emptyLinePlaceholder":1086},[1032,11001,11002,11005,11007,11009,11011,11013,11015,11017,11019,11022,11024,11026,11028,11030,11032],{"class":1034,"line":1411},[1032,11003,11004],{"class":1038},"  for",[1032,11006,5359],{"class":1049},[1032,11008,5362],{"class":1038},[1032,11010,5365],{"class":1049},[1032,11012,1226],{"class":1038},[1032,11014,3756],{"class":1042},[1032,11016,5372],{"class":1049},[1032,11018,1226],{"class":1038},[1032,11020,11021],{"class":1049}," node.children.",[1032,11023,4719],{"class":1042},[1032,11025,5382],{"class":1049},[1032,11027,5385],{"class":1038},[1032,11029,5388],{"class":1049},[1032,11031,5391],{"class":1038},[1032,11033,1214],{"class":1049},[1032,11035,11036,11039,11042,11045],{"class":1034,"line":1421},[1032,11037,11038],{"class":1195},"    traverse",[1032,11040,11041],{"class":1049},"(indent, node.",[1032,11043,11044],{"class":1195},"getChild",[1032,11046,11047],{"class":1049},"(i));\n",[1032,11049,11050],{"class":1034,"line":1433},[1032,11051,1306],{"class":1049},[1032,11053,11054],{"class":1034,"line":1442},[1032,11055,1312],{"class":1049},[1032,11057,11058],{"class":1034,"line":1458},[1032,11059,1087],{"emptyLinePlaceholder":1086},[1032,11061,11062,11064,11066,11068,11070,11072,11074,11077],{"class":1034,"line":1472},[1032,11063,1039],{"class":1038},[1032,11065,5167],{"class":1042},[1032,11067,1046],{"class":1038},[1032,11069,1530],{"class":1038},[1032,11071,10695],{"class":1195},[1032,11073,1207],{"class":1049},[1032,11075,11076],{"class":1059},"'root'",[1032,11078,1743],{"class":1049},[1032,11080,11081,11083,11086,11088,11090,11092,11094,11097],{"class":1034,"line":1480},[1032,11082,1039],{"class":1038},[1032,11084,11085],{"class":1042}," left",[1032,11087,1046],{"class":1038},[1032,11089,1530],{"class":1038},[1032,11091,10695],{"class":1195},[1032,11093,1207],{"class":1049},[1032,11095,11096],{"class":1059},"'left'",[1032,11098,1743],{"class":1049},[1032,11100,11101,11103,11106,11108,11110,11112,11114,11117],{"class":1034,"line":1494},[1032,11102,1039],{"class":1038},[1032,11104,11105],{"class":1042}," right",[1032,11107,1046],{"class":1038},[1032,11109,1530],{"class":1038},[1032,11111,10695],{"class":1195},[1032,11113,1207],{"class":1049},[1032,11115,11116],{"class":1059},"'right'",[1032,11118,1743],{"class":1049},[1032,11120,11121,11123,11126,11128,11130,11132,11134,11137],{"class":1034,"line":1506},[1032,11122,1039],{"class":1038},[1032,11124,11125],{"class":1042}," leftLeft",[1032,11127,1046],{"class":1038},[1032,11129,1530],{"class":1038},[1032,11131,10695],{"class":1195},[1032,11133,1207],{"class":1049},[1032,11135,11136],{"class":1059},"'leftLeft'",[1032,11138,1743],{"class":1049},[1032,11140,11141,11143,11146,11148,11150,11152,11154,11157],{"class":1034,"line":1513},[1032,11142,1039],{"class":1038},[1032,11144,11145],{"class":1042}," leftRight",[1032,11147,1046],{"class":1038},[1032,11149,1530],{"class":1038},[1032,11151,10695],{"class":1195},[1032,11153,1207],{"class":1049},[1032,11155,11156],{"class":1059},"'leftRight'",[1032,11158,1743],{"class":1049},[1032,11160,11161,11163,11166,11168,11170,11172,11174,11177],{"class":1034,"line":1519},[1032,11162,1039],{"class":1038},[1032,11164,11165],{"class":1042}," rightLeft",[1032,11167,1046],{"class":1038},[1032,11169,1530],{"class":1038},[1032,11171,10695],{"class":1195},[1032,11173,1207],{"class":1049},[1032,11175,11176],{"class":1059},"'rightLeft'",[1032,11178,1743],{"class":1049},[1032,11180,11181,11183,11186,11188,11190,11192,11194,11197],{"class":1034,"line":1524},[1032,11182,1039],{"class":1038},[1032,11184,11185],{"class":1042}," rightRight",[1032,11187,1046],{"class":1038},[1032,11189,1530],{"class":1038},[1032,11191,10695],{"class":1195},[1032,11193,1207],{"class":1049},[1032,11195,11196],{"class":1059},"'rightRight'",[1032,11198,1743],{"class":1049},[1032,11200,11201],{"class":1034,"line":1544},[1032,11202,1087],{"emptyLinePlaceholder":1086},[1032,11204,11205,11207,11209],{"class":1034,"line":1549},[1032,11206,5180],{"class":1049},[1032,11208,6834],{"class":1195},[1032,11210,11211],{"class":1049},"(left);\n",[1032,11213,11214,11216,11218],{"class":1034,"line":1554},[1032,11215,5180],{"class":1049},[1032,11217,6834],{"class":1195},[1032,11219,11220],{"class":1049},"(right);\n",[1032,11222,11223,11225,11228],{"class":1034,"line":1559},[1032,11224,5180],{"class":1049},[1032,11226,11227],{"class":1195},"remove",[1032,11229,11220],{"class":1049},[1032,11231,11232,11234,11236],{"class":1034,"line":1576},[1032,11233,5180],{"class":1049},[1032,11235,6834],{"class":1195},[1032,11237,11220],{"class":1049},[1032,11239,11240],{"class":1034,"line":1581},[1032,11241,1087],{"emptyLinePlaceholder":1086},[1032,11243,11244,11247,11249],{"class":1034,"line":1600},[1032,11245,11246],{"class":1049},"left.",[1032,11248,6834],{"class":1195},[1032,11250,11251],{"class":1049},"(leftLeft);\n",[1032,11253,11254,11256,11258],{"class":1034,"line":1615},[1032,11255,11246],{"class":1049},[1032,11257,6834],{"class":1195},[1032,11259,11260],{"class":1049},"(leftRight);\n",[1032,11262,11263],{"class":1034,"line":1631},[1032,11264,1087],{"emptyLinePlaceholder":1086},[1032,11266,11267,11270,11272],{"class":1034,"line":1642},[1032,11268,11269],{"class":1049},"right.",[1032,11271,6834],{"class":1195},[1032,11273,11274],{"class":1049},"(rightLeft);\n",[1032,11276,11277,11279,11281],{"class":1034,"line":1648},[1032,11278,11269],{"class":1049},[1032,11280,6834],{"class":1195},[1032,11282,11283],{"class":1049},"(rightRight);\n",[1032,11285,11286],{"class":1034,"line":1653},[1032,11287,1087],{"emptyLinePlaceholder":1086},[1032,11289,11290,11293,11295,11297],{"class":1034,"line":1669},[1032,11291,11292],{"class":1195},"traverse",[1032,11294,1207],{"class":1049},[1032,11296,5057],{"class":1042},[1032,11298,11299],{"class":1049},", tree);\n",[927,11301,11302,11303,11306,11307,5466,11309,5466,11311,5476,11313,11316,11317,11319,11320,11322],{},"In the example, a tree structure is created from ",[1029,11304,11305],{},"Node"," objects. Each node has a name and 4 methods: ",[1029,11308,6834],{},[1029,11310,11227],{},[1029,11312,11044],{},[1029,11314,11315],{},"hasChildren",". The methods are added to ",[1029,11318,11305],{},"'s prototype. This reduces the memory requirements as these methods are now shared by all nodes. ",[1029,11321,11305],{}," is fully recursive and there is no need for separate Component or Leaf objects.",[994,11324,11326],{"id":11325},"decorator","Decorator",[927,11328,2741,11329,11331],{},[967,11330,11326],{}," pattern is a design pattern that allows behavior to be added to an individual object, dynamically, without affecting the behavior of other objects from the same class.",[927,11333,11334],{},[948,11335],{"alt":11326,"src":11336},"\u002Fimages\u002Fblog\u002F2021-12-16-javascript-design-patterns\u002Fdecorator.png",[927,11338,2138,11339,11343],{},[967,11340,11341],{},[930,11342,11326],{}," pattern extends (decorates) an object’s behavior dynamically. The ability to add new behavior at runtime is accomplished by a Decorator object which ‘wraps itself’ around the original object. Multiple decorators can add or override functionality to the original object.",[1022,11345,11347],{"className":1024,"code":11346,"language":1026,"meta":1027,"style":1027},"class User {\n  constructor(name) {\n    this.name = name;\n  }\n\n  describe() {\n    console.log('User: ' + this.name);\n  }\n}\n\nclass DecoratedUser {\n  constructor(user, street, city) {\n    this.user = user;\n    this.name = user.name; \u002F\u002F ensures interface stays the same\n    this.street = street;\n    this.city = city;\n  }\n\n  say() {\n    console.log(`Decorated User: ${this.name}, ${this.street}, ${this.city}`);\n  }\n}\n\nconst user = new User('Kelly');\nuser.describe();\n\nconst decorated = new DecoratedUser(user, 'Broadway', 'New York');\ndecorated.say();\n",[1029,11348,11349,11358,11368,11378,11382,11386,11393,11411,11415,11419,11423,11432,11453,11465,11479,11491,11503,11507,11511,11518,11556,11560,11564,11568,11588,11598,11602,11628],{"__ignoreMap":1027},[1032,11350,11351,11353,11356],{"class":1034,"line":1035},[1032,11352,1192],{"class":1038},[1032,11354,11355],{"class":1195}," User",[1032,11357,1050],{"class":1049},[1032,11359,11360,11362,11364,11366],{"class":1034,"line":1053},[1032,11361,1204],{"class":1038},[1032,11363,1207],{"class":1049},[1032,11365,4757],{"class":1210},[1032,11367,1214],{"class":1049},[1032,11369,11370,11372,11374,11376],{"class":1034,"line":1066},[1032,11371,1220],{"class":1042},[1032,11373,4791],{"class":1049},[1032,11375,1226],{"class":1038},[1032,11377,4796],{"class":1049},[1032,11379,11380],{"class":1034,"line":1077},[1032,11381,1306],{"class":1049},[1032,11383,11384],{"class":1034,"line":1083},[1032,11385,1087],{"emptyLinePlaceholder":1086},[1032,11387,11388,11391],{"class":1034,"line":1090},[1032,11389,11390],{"class":1195},"  describe",[1032,11392,1868],{"class":1049},[1032,11394,11395,11397,11399,11401,11404,11406,11408],{"class":1034,"line":1102},[1032,11396,1873],{"class":1049},[1032,11398,1728],{"class":1195},[1032,11400,1207],{"class":1049},[1032,11402,11403],{"class":1059},"'User: '",[1032,11405,5429],{"class":1038},[1032,11407,1533],{"class":1042},[1032,11409,11410],{"class":1049},".name);\n",[1032,11412,11413],{"class":1034,"line":1113},[1032,11414,1306],{"class":1049},[1032,11416,11417],{"class":1034,"line":1124},[1032,11418,1312],{"class":1049},[1032,11420,11421],{"class":1034,"line":1135},[1032,11422,1087],{"emptyLinePlaceholder":1086},[1032,11424,11425,11427,11430],{"class":1034,"line":1140},[1032,11426,1192],{"class":1038},[1032,11428,11429],{"class":1195}," DecoratedUser",[1032,11431,1050],{"class":1049},[1032,11433,11434,11436,11438,11441,11443,11446,11448,11451],{"class":1034,"line":1145},[1032,11435,1204],{"class":1038},[1032,11437,1207],{"class":1049},[1032,11439,11440],{"class":1210},"user",[1032,11442,2819],{"class":1049},[1032,11444,11445],{"class":1210},"street",[1032,11447,2819],{"class":1049},[1032,11449,11450],{"class":1210},"city",[1032,11452,1214],{"class":1049},[1032,11454,11455,11457,11460,11462],{"class":1034,"line":1157},[1032,11456,1220],{"class":1042},[1032,11458,11459],{"class":1049},".user ",[1032,11461,1226],{"class":1038},[1032,11463,11464],{"class":1049}," user;\n",[1032,11466,11467,11469,11471,11473,11476],{"class":1034,"line":1168},[1032,11468,1220],{"class":1042},[1032,11470,4791],{"class":1049},[1032,11472,1226],{"class":1038},[1032,11474,11475],{"class":1049}," user.name; ",[1032,11477,11478],{"class":1718},"\u002F\u002F ensures interface stays the same\n",[1032,11480,11481,11483,11486,11488],{"class":1034,"line":1179},[1032,11482,1220],{"class":1042},[1032,11484,11485],{"class":1049},".street ",[1032,11487,1226],{"class":1038},[1032,11489,11490],{"class":1049}," street;\n",[1032,11492,11493,11495,11498,11500],{"class":1034,"line":1184},[1032,11494,1220],{"class":1042},[1032,11496,11497],{"class":1049},".city ",[1032,11499,1226],{"class":1038},[1032,11501,11502],{"class":1049}," city;\n",[1032,11504,11505],{"class":1034,"line":1189},[1032,11506,1306],{"class":1049},[1032,11508,11509],{"class":1034,"line":1201},[1032,11510,1087],{"emptyLinePlaceholder":1086},[1032,11512,11513,11516],{"class":1034,"line":1217},[1032,11514,11515],{"class":1195},"  say",[1032,11517,1868],{"class":1049},[1032,11519,11520,11522,11524,11526,11529,11531,11533,11535,11538,11540,11542,11544,11546,11548,11550,11552,11554],{"class":1034,"line":1232},[1032,11521,1873],{"class":1049},[1032,11523,1728],{"class":1195},[1032,11525,1207],{"class":1049},[1032,11527,11528],{"class":1059},"`Decorated User: ${",[1032,11530,2298],{"class":1042},[1032,11532,1271],{"class":1059},[1032,11534,4757],{"class":1049},[1032,11536,11537],{"class":1059},"}, ${",[1032,11539,2298],{"class":1042},[1032,11541,1271],{"class":1059},[1032,11543,11445],{"class":1049},[1032,11545,11537],{"class":1059},[1032,11547,2298],{"class":1042},[1032,11549,1271],{"class":1059},[1032,11551,11450],{"class":1049},[1032,11553,2350],{"class":1059},[1032,11555,1743],{"class":1049},[1032,11557,11558],{"class":1034,"line":1254},[1032,11559,1306],{"class":1049},[1032,11561,11562],{"class":1034,"line":1279},[1032,11563,1312],{"class":1049},[1032,11565,11566],{"class":1034,"line":1303},[1032,11567,1087],{"emptyLinePlaceholder":1086},[1032,11569,11570,11572,11575,11577,11579,11581,11583,11586],{"class":1034,"line":1309},[1032,11571,1039],{"class":1038},[1032,11573,11574],{"class":1042}," user",[1032,11576,1046],{"class":1038},[1032,11578,1530],{"class":1038},[1032,11580,11355],{"class":1195},[1032,11582,1207],{"class":1049},[1032,11584,11585],{"class":1059},"'Kelly'",[1032,11587,1743],{"class":1049},[1032,11589,11590,11593,11596],{"class":1034,"line":1315},[1032,11591,11592],{"class":1049},"user.",[1032,11594,11595],{"class":1195},"describe",[1032,11597,1573],{"class":1049},[1032,11599,11600],{"class":1034,"line":1320},[1032,11601,1087],{"emptyLinePlaceholder":1086},[1032,11603,11604,11606,11609,11611,11613,11615,11618,11621,11623,11626],{"class":1034,"line":1330},[1032,11605,1039],{"class":1038},[1032,11607,11608],{"class":1042}," decorated",[1032,11610,1046],{"class":1038},[1032,11612,1530],{"class":1038},[1032,11614,11429],{"class":1195},[1032,11616,11617],{"class":1049},"(user, ",[1032,11619,11620],{"class":1059},"'Broadway'",[1032,11622,2819],{"class":1049},[1032,11624,11625],{"class":1059},"'New York'",[1032,11627,1743],{"class":1049},[1032,11629,11630,11633,11636],{"class":1034,"line":1341},[1032,11631,11632],{"class":1049},"decorated.",[1032,11634,11635],{"class":1195},"say",[1032,11637,1573],{"class":1049},[927,11639,11640,11641,11644,11645,11648,11649,11652,11653,11656,11657,11659,11660,11662],{},"In the example code, a ",[1029,11642,11643],{},"User"," object is decorated (enhanced) by a ",[1029,11646,11647],{},"DecoratedUser"," object. It extends the User with several address-based properties. The original interface must stay the same, which explains why ",[1029,11650,11651],{},"user.name"," is assigned to ",[1029,11654,11655],{},"this.name",". Also, the ",[1029,11658,11635],{}," method of DecoratedUser hides the ",[1029,11661,11635],{}," method of User.",[994,11664,11666],{"id":11665},"façade",[967,11667,11668],{},"Façade",[927,11670,2741,11671,11675],{},[967,11672,11673],{},[930,11674,11668],{}," pattern is a structural design pattern commonly used in object-oriented programming. Analogous to a facade in architecture, a facade is an object that serves as a front-facing interface masking more complex underlying or structural code.",[927,11677,11678],{},[948,11679],{"alt":11668,"src":11680},"\u002Fimages\u002Fblog\u002F2021-12-16-javascript-design-patterns\u002Ffacade.png",[927,11682,2138,11683,11687],{},[967,11684,11685],{},[930,11686,11668],{}," pattern provides an interface that shields clients from complex functionality in one or more subsystems. It is a simple pattern that may seem trivial but it is powerful and extremely useful. It is often present in systems that are built around a multi-layer architecture.",[1022,11689,11691],{"className":1024,"code":11690,"language":1026,"meta":1027,"style":1027},"const APPROVED_LIST = ['John', 'Lisa'];\n\nclass Mortgage {\n  constructor(name) {\n    this.name = name;\n  }\n\n  applyFor(amount) {\n    \u002F\u002F access multiple subsystems\n    let result = 'approved';\n\n    if (!new Bank().verify(this.name, amount)) {\n      result = 'denied';\n    } else if (!new Credit().get(this.name)) {\n      result = 'denied';\n    } else if (!new Background().check(this.name)) {\n      result = 'denied';\n    }\n    return `${this.name} has been ${result} for a ${amount} mortgage`;\n  }\n}\n\nclass Bank {\n  verify(name, amount) {\n    if (APPROVED_LIST.includes(name) && amount \u003C 200000) {\n      return true;\n    }\n\n    return false;\n  }\n}\n\nclass Credit {\n  get(name) {\n    if (APPROVED_LIST.includes(name)) {\n      return true;\n    }\n    return false;\n  }\n}\n\nclass Background {\n  check(name) {\n    if (APPROVED_LIST.includes(name)) {\n      return true;\n    }\n    return false;\n  }\n}\n\nconst mortgage = new Mortgage('John');\nconst result = mortgage.applyFor(100000);\n\nconsole.log(result);\n",[1029,11692,11693,11714,11718,11727,11737,11747,11751,11755,11766,11771,11786,11790,11815,11827,11853,11863,11889,11899,11903,11932,11936,11940,11944,11952,11967,11997,12005,12009,12013,12022,12026,12030,12034,12042,12052,12067,12075,12079,12087,12091,12095,12099,12107,12118,12132,12140,12144,12152,12156,12160,12164,12183,12204,12208],{"__ignoreMap":1027},[1032,11694,11695,11697,11700,11702,11704,11707,11709,11712],{"class":1034,"line":1035},[1032,11696,1039],{"class":1038},[1032,11698,11699],{"class":1042}," APPROVED_LIST",[1032,11701,1046],{"class":1038},[1032,11703,5760],{"class":1049},[1032,11705,11706],{"class":1059},"'John'",[1032,11708,2819],{"class":1049},[1032,11710,11711],{"class":1059},"'Lisa'",[1032,11713,5600],{"class":1049},[1032,11715,11716],{"class":1034,"line":1053},[1032,11717,1087],{"emptyLinePlaceholder":1086},[1032,11719,11720,11722,11725],{"class":1034,"line":1066},[1032,11721,1192],{"class":1038},[1032,11723,11724],{"class":1195}," Mortgage",[1032,11726,1050],{"class":1049},[1032,11728,11729,11731,11733,11735],{"class":1034,"line":1077},[1032,11730,1204],{"class":1038},[1032,11732,1207],{"class":1049},[1032,11734,4757],{"class":1210},[1032,11736,1214],{"class":1049},[1032,11738,11739,11741,11743,11745],{"class":1034,"line":1083},[1032,11740,1220],{"class":1042},[1032,11742,4791],{"class":1049},[1032,11744,1226],{"class":1038},[1032,11746,4796],{"class":1049},[1032,11748,11749],{"class":1034,"line":1090},[1032,11750,1306],{"class":1049},[1032,11752,11753],{"class":1034,"line":1102},[1032,11754,1087],{"emptyLinePlaceholder":1086},[1032,11756,11757,11760,11762,11764],{"class":1034,"line":1113},[1032,11758,11759],{"class":1195},"  applyFor",[1032,11761,1207],{"class":1049},[1032,11763,3447],{"class":1210},[1032,11765,1214],{"class":1049},[1032,11767,11768],{"class":1034,"line":1124},[1032,11769,11770],{"class":1718},"    \u002F\u002F access multiple subsystems\n",[1032,11772,11773,11776,11779,11781,11784],{"class":1034,"line":1135},[1032,11774,11775],{"class":1038},"    let",[1032,11777,11778],{"class":1049}," result ",[1032,11780,1226],{"class":1038},[1032,11782,11783],{"class":1059}," 'approved'",[1032,11785,1251],{"class":1049},[1032,11787,11788],{"class":1034,"line":1140},[1032,11789,1087],{"emptyLinePlaceholder":1086},[1032,11791,11792,11794,11796,11799,11802,11805,11808,11810,11812],{"class":1034,"line":1145},[1032,11793,3212],{"class":1038},[1032,11795,5359],{"class":1049},[1032,11797,11798],{"class":1038},"!new",[1032,11800,11801],{"class":1195}," Bank",[1032,11803,11804],{"class":1049},"().",[1032,11806,11807],{"class":1195},"verify",[1032,11809,1207],{"class":1049},[1032,11811,2298],{"class":1042},[1032,11813,11814],{"class":1049},".name, amount)) {\n",[1032,11816,11817,11820,11822,11825],{"class":1034,"line":1157},[1032,11818,11819],{"class":1049},"      result ",[1032,11821,1226],{"class":1038},[1032,11823,11824],{"class":1059}," 'denied'",[1032,11826,1251],{"class":1049},[1032,11828,11829,11831,11833,11835,11837,11839,11842,11844,11846,11848,11850],{"class":1034,"line":1168},[1032,11830,4903],{"class":1049},[1032,11832,4906],{"class":1038},[1032,11834,4909],{"class":1038},[1032,11836,5359],{"class":1049},[1032,11838,11798],{"class":1038},[1032,11840,11841],{"class":1195}," Credit",[1032,11843,11804],{"class":1049},[1032,11845,6919],{"class":1195},[1032,11847,1207],{"class":1049},[1032,11849,2298],{"class":1042},[1032,11851,11852],{"class":1049},".name)) {\n",[1032,11854,11855,11857,11859,11861],{"class":1034,"line":1179},[1032,11856,11819],{"class":1049},[1032,11858,1226],{"class":1038},[1032,11860,11824],{"class":1059},[1032,11862,1251],{"class":1049},[1032,11864,11865,11867,11869,11871,11873,11875,11878,11880,11883,11885,11887],{"class":1034,"line":1184},[1032,11866,4903],{"class":1049},[1032,11868,4906],{"class":1038},[1032,11870,4909],{"class":1038},[1032,11872,5359],{"class":1049},[1032,11874,11798],{"class":1038},[1032,11876,11877],{"class":1195}," Background",[1032,11879,11804],{"class":1049},[1032,11881,11882],{"class":1195},"check",[1032,11884,1207],{"class":1049},[1032,11886,2298],{"class":1042},[1032,11888,11852],{"class":1049},[1032,11890,11891,11893,11895,11897],{"class":1034,"line":1189},[1032,11892,11819],{"class":1049},[1032,11894,1226],{"class":1038},[1032,11896,11824],{"class":1059},[1032,11898,1251],{"class":1049},[1032,11900,11901],{"class":1034,"line":1201},[1032,11902,1516],{"class":1049},[1032,11904,11905,11907,11910,11912,11914,11916,11919,11922,11925,11927,11930],{"class":1034,"line":1217},[1032,11906,1527],{"class":1038},[1032,11908,11909],{"class":1059}," `${",[1032,11911,2298],{"class":1042},[1032,11913,1271],{"class":1059},[1032,11915,4757],{"class":1049},[1032,11917,11918],{"class":1059},"} has been ${",[1032,11920,11921],{"class":1049},"result",[1032,11923,11924],{"class":1059},"} for a ${",[1032,11926,3447],{"class":1049},[1032,11928,11929],{"class":1059},"} mortgage`",[1032,11931,1251],{"class":1049},[1032,11933,11934],{"class":1034,"line":1232},[1032,11935,1306],{"class":1049},[1032,11937,11938],{"class":1034,"line":1254},[1032,11939,1312],{"class":1049},[1032,11941,11942],{"class":1034,"line":1279},[1032,11943,1087],{"emptyLinePlaceholder":1086},[1032,11945,11946,11948,11950],{"class":1034,"line":1303},[1032,11947,1192],{"class":1038},[1032,11949,11801],{"class":1195},[1032,11951,1050],{"class":1049},[1032,11953,11954,11957,11959,11961,11963,11965],{"class":1034,"line":1309},[1032,11955,11956],{"class":1195},"  verify",[1032,11958,1207],{"class":1049},[1032,11960,4757],{"class":1210},[1032,11962,2819],{"class":1049},[1032,11964,3447],{"class":1210},[1032,11966,1214],{"class":1049},[1032,11968,11969,11971,11973,11976,11978,11981,11984,11987,11990,11992,11995],{"class":1034,"line":1315},[1032,11970,3212],{"class":1038},[1032,11972,5359],{"class":1049},[1032,11974,11975],{"class":1042},"APPROVED_LIST",[1032,11977,1271],{"class":1049},[1032,11979,11980],{"class":1195},"includes",[1032,11982,11983],{"class":1049},"(name) ",[1032,11985,11986],{"class":1038},"&&",[1032,11988,11989],{"class":1049}," amount ",[1032,11991,5385],{"class":1038},[1032,11993,11994],{"class":1042}," 200000",[1032,11996,1214],{"class":1049},[1032,11998,11999,12001,12003],{"class":1034,"line":1320},[1032,12000,3220],{"class":1038},[1032,12002,8537],{"class":1042},[1032,12004,1251],{"class":1049},[1032,12006,12007],{"class":1034,"line":1330},[1032,12008,1516],{"class":1049},[1032,12010,12011],{"class":1034,"line":1341},[1032,12012,1087],{"emptyLinePlaceholder":1086},[1032,12014,12015,12017,12020],{"class":1034,"line":1352},[1032,12016,1527],{"class":1038},[1032,12018,12019],{"class":1042}," false",[1032,12021,1251],{"class":1049},[1032,12023,12024],{"class":1034,"line":1374},[1032,12025,1306],{"class":1049},[1032,12027,12028],{"class":1034,"line":1396},[1032,12029,1312],{"class":1049},[1032,12031,12032],{"class":1034,"line":1401},[1032,12033,1087],{"emptyLinePlaceholder":1086},[1032,12035,12036,12038,12040],{"class":1034,"line":1406},[1032,12037,1192],{"class":1038},[1032,12039,11841],{"class":1195},[1032,12041,1050],{"class":1049},[1032,12043,12044,12046,12048,12050],{"class":1034,"line":1411},[1032,12045,6736],{"class":1195},[1032,12047,1207],{"class":1049},[1032,12049,4757],{"class":1210},[1032,12051,1214],{"class":1049},[1032,12053,12054,12056,12058,12060,12062,12064],{"class":1034,"line":1421},[1032,12055,3212],{"class":1038},[1032,12057,5359],{"class":1049},[1032,12059,11975],{"class":1042},[1032,12061,1271],{"class":1049},[1032,12063,11980],{"class":1195},[1032,12065,12066],{"class":1049},"(name)) {\n",[1032,12068,12069,12071,12073],{"class":1034,"line":1433},[1032,12070,3220],{"class":1038},[1032,12072,8537],{"class":1042},[1032,12074,1251],{"class":1049},[1032,12076,12077],{"class":1034,"line":1442},[1032,12078,1516],{"class":1049},[1032,12080,12081,12083,12085],{"class":1034,"line":1458},[1032,12082,1527],{"class":1038},[1032,12084,12019],{"class":1042},[1032,12086,1251],{"class":1049},[1032,12088,12089],{"class":1034,"line":1472},[1032,12090,1306],{"class":1049},[1032,12092,12093],{"class":1034,"line":1480},[1032,12094,1312],{"class":1049},[1032,12096,12097],{"class":1034,"line":1494},[1032,12098,1087],{"emptyLinePlaceholder":1086},[1032,12100,12101,12103,12105],{"class":1034,"line":1506},[1032,12102,1192],{"class":1038},[1032,12104,11877],{"class":1195},[1032,12106,1050],{"class":1049},[1032,12108,12109,12112,12114,12116],{"class":1034,"line":1513},[1032,12110,12111],{"class":1195},"  check",[1032,12113,1207],{"class":1049},[1032,12115,4757],{"class":1210},[1032,12117,1214],{"class":1049},[1032,12119,12120,12122,12124,12126,12128,12130],{"class":1034,"line":1519},[1032,12121,3212],{"class":1038},[1032,12123,5359],{"class":1049},[1032,12125,11975],{"class":1042},[1032,12127,1271],{"class":1049},[1032,12129,11980],{"class":1195},[1032,12131,12066],{"class":1049},[1032,12133,12134,12136,12138],{"class":1034,"line":1524},[1032,12135,3220],{"class":1038},[1032,12137,8537],{"class":1042},[1032,12139,1251],{"class":1049},[1032,12141,12142],{"class":1034,"line":1544},[1032,12143,1516],{"class":1049},[1032,12145,12146,12148,12150],{"class":1034,"line":1549},[1032,12147,1527],{"class":1038},[1032,12149,12019],{"class":1042},[1032,12151,1251],{"class":1049},[1032,12153,12154],{"class":1034,"line":1554},[1032,12155,1306],{"class":1049},[1032,12157,12158],{"class":1034,"line":1559},[1032,12159,1312],{"class":1049},[1032,12161,12162],{"class":1034,"line":1576},[1032,12163,1087],{"emptyLinePlaceholder":1086},[1032,12165,12166,12168,12171,12173,12175,12177,12179,12181],{"class":1034,"line":1581},[1032,12167,1039],{"class":1038},[1032,12169,12170],{"class":1042}," mortgage",[1032,12172,1046],{"class":1038},[1032,12174,1530],{"class":1038},[1032,12176,11724],{"class":1195},[1032,12178,1207],{"class":1049},[1032,12180,11706],{"class":1059},[1032,12182,1743],{"class":1049},[1032,12184,12185,12187,12190,12192,12195,12198,12200,12202],{"class":1034,"line":1600},[1032,12186,1039],{"class":1038},[1032,12188,12189],{"class":1042}," result",[1032,12191,1046],{"class":1038},[1032,12193,12194],{"class":1049}," mortgage.",[1032,12196,12197],{"class":1195},"applyFor",[1032,12199,1207],{"class":1049},[1032,12201,9141],{"class":1042},[1032,12203,1743],{"class":1049},[1032,12205,12206],{"class":1034,"line":1615},[1032,12207,1087],{"emptyLinePlaceholder":1086},[1032,12209,12210,12212,12214],{"class":1034,"line":1631},[1032,12211,1725],{"class":1049},[1032,12213,1728],{"class":1195},[1032,12215,12216],{"class":1049},"(result);\n",[927,12218,2138,12219,12222,12223,12225],{},[1029,12220,12221],{},"Mortgage"," object is the Façade in the example code. It presents a simple interface to the client with only a single method: ",[1029,12224,12197],{},". But underneath this simple API lies considerable complexity.",[927,12227,12228,12229,12231,12232,5466,12235,5476,12238,1271],{},"The applicant's name is passed into the Mortgage constructor function. Then the ",[1029,12230,12197],{}," method is called with the requested loan amount. Internally, this method uses services from 3 separate subsystems that are complex and possibly take some time to process; they are ",[1029,12233,12234],{},"Bank",[1029,12236,12237],{},"Credit",[1029,12239,12240],{},"Background",[927,12242,12243],{},"Based on several criteria (bank statements, credit reports, and criminal background) the applicant is either accepted or denied for the requested loan.",[994,12245,12247],{"id":12246},"flyweight",[967,12248,12249],{},"Flyweight",[927,12251,12252],{},"A flyweight is an object that minimizes memory usage by sharing as much data as possible with other similar objects.",[927,12254,12255],{},[948,12256],{"alt":12249,"src":12257},"\u002Fimages\u002Fblog\u002F2021-12-16-javascript-design-patterns\u002Fflyweight.png",[927,12259,2138,12260,12264],{},[967,12261,12262],{},[930,12263,12249],{}," pattern conserves memory by sharing large numbers of fine-grained objects efficiently. Shared flyweight objects are immutable, that is, they cannot be changed as they represent the characteristics that are shared with other objects.",[1022,12266,12268],{"className":1024,"code":12267,"language":1026,"meta":1027,"style":1027},"class Flyweight {\n  contructor(make, model, processor) {\n    this.make = make;\n    this.model = model;\n    this.processor = processor;\n  }\n}\n\nclass FlyWeightFactory {\n  static flyweights = {};\n  static count = 0;\n\n  static get(make, model, processor) {\n    if (!FlyWeightFactory.flyweights[make + model]) {\n      FlyWeightFactory.flyweights[make + model] = new Flyweight(\n        make,\n        model,\n        processor,\n      );\n    }\n\n    return FlyWeightFactory.flyweights[make + model];\n  }\n\n  static getCount() {\n    for (let f in FlyWeightFactory.flyweights) FlyWeightFactory.count++;\n    return FlyWeightFactory.count;\n  }\n}\n\nlet count = 0;\n\nclass ComputerCollection {\n  computers = {};\n\n  add(make, model, processor, memory, tag) {\n    computers[tag] = new Computer(make, model, processor, memory, tag);\n    count++;\n  }\n\n  get(tag) {\n    return computers[tag];\n  }\n\n  getCount() {\n    return count;\n  }\n}\n\nclass Computer {\n  constructor(make, model, processor, memory, tag) {\n    this.flyweight = FlyWeightFactory.get(make, model, processor);\n    this.memory = memory;\n    this.tag = tag;\n    this.getMake = function () {\n      return this.flyweight.make;\n    };\n  }\n}\n\nconst computers = new ComputerCollection();\n\ncomputers.add('Apple', 'MacBook Pro', 'Intel', '5G', 'Y755P');\ncomputers.add('Apple', 'MacBook Pro', 'Intel', '6G', 'X997T');\ncomputers.add('Apple', 'MacBook Pro', 'Intel', '2G', 'U8U80');\ncomputers.add('Apple', 'MacBook Pro', 'Intel', '2G', 'NT777');\ncomputers.add('Apple', 'MacBook Pro', 'Intel', '2G', '0J88A');\ncomputers.add('HP', 'Envy', 'Intel', '4G', 'CNU883701');\ncomputers.add('HP', 'Envy', 'Intel', '2G', 'TXU003283');\n\nconsole.log('Computers: ' + computers.getCount());\nconsole.log('Flyweights: ' + FlyWeightFactory.getCount());\n",[1029,12269,12270,12279,12300,12312,12322,12334,12338,12342,12346,12355,12367,12379,12383,12404,12421,12439,12444,12449,12454,12459,12463,12467,12479,12483,12487,12496,12517,12524,12528,12532,12536,12548,12552,12561,12570,12574,12602,12617,12626,12630,12634,12644,12651,12655,12659,12666,12673,12677,12681,12685,12693,12719,12736,12748,12760,12775,12784,12788,12792,12796,12800,12815,12819,12852,12882,12912,12941,12970,13002,13031,13035,13056],{"__ignoreMap":1027},[1032,12271,12272,12274,12277],{"class":1034,"line":1035},[1032,12273,1192],{"class":1038},[1032,12275,12276],{"class":1195}," Flyweight",[1032,12278,1050],{"class":1049},[1032,12280,12281,12284,12286,12289,12291,12293,12295,12298],{"class":1034,"line":1053},[1032,12282,12283],{"class":1195},"  contructor",[1032,12285,1207],{"class":1049},[1032,12287,12288],{"class":1210},"make",[1032,12290,2819],{"class":1049},[1032,12292,2822],{"class":1210},[1032,12294,2819],{"class":1049},[1032,12296,12297],{"class":1210},"processor",[1032,12299,1214],{"class":1049},[1032,12301,12302,12304,12307,12309],{"class":1034,"line":1066},[1032,12303,1220],{"class":1042},[1032,12305,12306],{"class":1049},".make ",[1032,12308,1226],{"class":1038},[1032,12310,12311],{"class":1049}," make;\n",[1032,12313,12314,12316,12318,12320],{"class":1034,"line":1077},[1032,12315,1220],{"class":1042},[1032,12317,2841],{"class":1049},[1032,12319,1226],{"class":1038},[1032,12321,2846],{"class":1049},[1032,12323,12324,12326,12329,12331],{"class":1034,"line":1083},[1032,12325,1220],{"class":1042},[1032,12327,12328],{"class":1049},".processor ",[1032,12330,1226],{"class":1038},[1032,12332,12333],{"class":1049}," processor;\n",[1032,12335,12336],{"class":1034,"line":1090},[1032,12337,1306],{"class":1049},[1032,12339,12340],{"class":1034,"line":1102},[1032,12341,1312],{"class":1049},[1032,12343,12344],{"class":1034,"line":1113},[1032,12345,1087],{"emptyLinePlaceholder":1086},[1032,12347,12348,12350,12353],{"class":1034,"line":1124},[1032,12349,1192],{"class":1038},[1032,12351,12352],{"class":1195}," FlyWeightFactory",[1032,12354,1050],{"class":1049},[1032,12356,12357,12360,12363,12365],{"class":1034,"line":1135},[1032,12358,12359],{"class":1038},"  static",[1032,12361,12362],{"class":1210}," flyweights",[1032,12364,1046],{"class":1038},[1032,12366,6065],{"class":1049},[1032,12368,12369,12371,12373,12375,12377],{"class":1034,"line":1140},[1032,12370,12359],{"class":1038},[1032,12372,3512],{"class":1210},[1032,12374,1046],{"class":1038},[1032,12376,3756],{"class":1042},[1032,12378,1251],{"class":1049},[1032,12380,12381],{"class":1034,"line":1145},[1032,12382,1087],{"emptyLinePlaceholder":1086},[1032,12384,12385,12387,12390,12392,12394,12396,12398,12400,12402],{"class":1034,"line":1157},[1032,12386,12359],{"class":1038},[1032,12388,12389],{"class":1195}," get",[1032,12391,1207],{"class":1049},[1032,12393,12288],{"class":1210},[1032,12395,2819],{"class":1049},[1032,12397,2822],{"class":1210},[1032,12399,2819],{"class":1049},[1032,12401,12297],{"class":1210},[1032,12403,1214],{"class":1049},[1032,12405,12406,12408,12410,12413,12416,12418],{"class":1034,"line":1168},[1032,12407,3212],{"class":1038},[1032,12409,5359],{"class":1049},[1032,12411,12412],{"class":1038},"!",[1032,12414,12415],{"class":1049},"FlyWeightFactory.flyweights[make ",[1032,12417,3910],{"class":1038},[1032,12419,12420],{"class":1049}," model]) {\n",[1032,12422,12423,12426,12428,12431,12433,12435,12437],{"class":1034,"line":1179},[1032,12424,12425],{"class":1049},"      FlyWeightFactory.flyweights[make ",[1032,12427,3910],{"class":1038},[1032,12429,12430],{"class":1049}," model] ",[1032,12432,1226],{"class":1038},[1032,12434,1530],{"class":1038},[1032,12436,12276],{"class":1195},[1032,12438,9319],{"class":1049},[1032,12440,12441],{"class":1034,"line":1184},[1032,12442,12443],{"class":1049},"        make,\n",[1032,12445,12446],{"class":1034,"line":1189},[1032,12447,12448],{"class":1049},"        model,\n",[1032,12450,12451],{"class":1034,"line":1201},[1032,12452,12453],{"class":1049},"        processor,\n",[1032,12455,12456],{"class":1034,"line":1217},[1032,12457,12458],{"class":1049},"      );\n",[1032,12460,12461],{"class":1034,"line":1232},[1032,12462,1516],{"class":1049},[1032,12464,12465],{"class":1034,"line":1254},[1032,12466,1087],{"emptyLinePlaceholder":1086},[1032,12468,12469,12471,12474,12476],{"class":1034,"line":1279},[1032,12470,1527],{"class":1038},[1032,12472,12473],{"class":1049}," FlyWeightFactory.flyweights[make ",[1032,12475,3910],{"class":1038},[1032,12477,12478],{"class":1049}," model];\n",[1032,12480,12481],{"class":1034,"line":1303},[1032,12482,1306],{"class":1049},[1032,12484,12485],{"class":1034,"line":1309},[1032,12486,1087],{"emptyLinePlaceholder":1086},[1032,12488,12489,12491,12494],{"class":1034,"line":1315},[1032,12490,12359],{"class":1038},[1032,12492,12493],{"class":1195}," getCount",[1032,12495,1868],{"class":1049},[1032,12497,12498,12500,12502,12504,12507,12510,12513,12515],{"class":1034,"line":1320},[1032,12499,5687],{"class":1038},[1032,12501,5359],{"class":1049},[1032,12503,5362],{"class":1038},[1032,12505,12506],{"class":1049}," f ",[1032,12508,12509],{"class":1038},"in",[1032,12511,12512],{"class":1049}," FlyWeightFactory.flyweights) FlyWeightFactory.count",[1032,12514,5391],{"class":1038},[1032,12516,1251],{"class":1049},[1032,12518,12519,12521],{"class":1034,"line":1330},[1032,12520,1527],{"class":1038},[1032,12522,12523],{"class":1049}," FlyWeightFactory.count;\n",[1032,12525,12526],{"class":1034,"line":1341},[1032,12527,1306],{"class":1049},[1032,12529,12530],{"class":1034,"line":1352},[1032,12531,1312],{"class":1049},[1032,12533,12534],{"class":1034,"line":1374},[1032,12535,1087],{"emptyLinePlaceholder":1086},[1032,12537,12538,12540,12542,12544,12546],{"class":1034,"line":1396},[1032,12539,5362],{"class":1038},[1032,12541,3544],{"class":1049},[1032,12543,1226],{"class":1038},[1032,12545,3756],{"class":1042},[1032,12547,1251],{"class":1049},[1032,12549,12550],{"class":1034,"line":1401},[1032,12551,1087],{"emptyLinePlaceholder":1086},[1032,12553,12554,12556,12559],{"class":1034,"line":1406},[1032,12555,1192],{"class":1038},[1032,12557,12558],{"class":1195}," ComputerCollection",[1032,12560,1050],{"class":1049},[1032,12562,12563,12566,12568],{"class":1034,"line":1411},[1032,12564,12565],{"class":1210},"  computers",[1032,12567,1046],{"class":1038},[1032,12569,6065],{"class":1049},[1032,12571,12572],{"class":1034,"line":1421},[1032,12573,1087],{"emptyLinePlaceholder":1086},[1032,12575,12576,12578,12580,12582,12584,12586,12588,12590,12592,12595,12597,12600],{"class":1034,"line":1433},[1032,12577,3888],{"class":1195},[1032,12579,1207],{"class":1049},[1032,12581,12288],{"class":1210},[1032,12583,2819],{"class":1049},[1032,12585,2822],{"class":1210},[1032,12587,2819],{"class":1049},[1032,12589,12297],{"class":1210},[1032,12591,2819],{"class":1049},[1032,12593,12594],{"class":1210},"memory",[1032,12596,2819],{"class":1049},[1032,12598,12599],{"class":1210},"tag",[1032,12601,1214],{"class":1049},[1032,12603,12604,12607,12609,12611,12614],{"class":1034,"line":1442},[1032,12605,12606],{"class":1049},"    computers[tag] ",[1032,12608,1226],{"class":1038},[1032,12610,1530],{"class":1038},[1032,12612,12613],{"class":1195}," Computer",[1032,12615,12616],{"class":1049},"(make, model, processor, memory, tag);\n",[1032,12618,12619,12622,12624],{"class":1034,"line":1458},[1032,12620,12621],{"class":1049},"    count",[1032,12623,5391],{"class":1038},[1032,12625,1251],{"class":1049},[1032,12627,12628],{"class":1034,"line":1472},[1032,12629,1306],{"class":1049},[1032,12631,12632],{"class":1034,"line":1480},[1032,12633,1087],{"emptyLinePlaceholder":1086},[1032,12635,12636,12638,12640,12642],{"class":1034,"line":1494},[1032,12637,6736],{"class":1195},[1032,12639,1207],{"class":1049},[1032,12641,12599],{"class":1210},[1032,12643,1214],{"class":1049},[1032,12645,12646,12648],{"class":1034,"line":1506},[1032,12647,1527],{"class":1038},[1032,12649,12650],{"class":1049}," computers[tag];\n",[1032,12652,12653],{"class":1034,"line":1513},[1032,12654,1306],{"class":1049},[1032,12656,12657],{"class":1034,"line":1519},[1032,12658,1087],{"emptyLinePlaceholder":1086},[1032,12660,12661,12664],{"class":1034,"line":1524},[1032,12662,12663],{"class":1195},"  getCount",[1032,12665,1868],{"class":1049},[1032,12667,12668,12670],{"class":1034,"line":1544},[1032,12669,1527],{"class":1038},[1032,12671,12672],{"class":1049}," count;\n",[1032,12674,12675],{"class":1034,"line":1549},[1032,12676,1306],{"class":1049},[1032,12678,12679],{"class":1034,"line":1554},[1032,12680,1312],{"class":1049},[1032,12682,12683],{"class":1034,"line":1559},[1032,12684,1087],{"emptyLinePlaceholder":1086},[1032,12686,12687,12689,12691],{"class":1034,"line":1576},[1032,12688,1192],{"class":1038},[1032,12690,12613],{"class":1195},[1032,12692,1050],{"class":1049},[1032,12694,12695,12697,12699,12701,12703,12705,12707,12709,12711,12713,12715,12717],{"class":1034,"line":1581},[1032,12696,1204],{"class":1038},[1032,12698,1207],{"class":1049},[1032,12700,12288],{"class":1210},[1032,12702,2819],{"class":1049},[1032,12704,2822],{"class":1210},[1032,12706,2819],{"class":1049},[1032,12708,12297],{"class":1210},[1032,12710,2819],{"class":1049},[1032,12712,12594],{"class":1210},[1032,12714,2819],{"class":1049},[1032,12716,12599],{"class":1210},[1032,12718,1214],{"class":1049},[1032,12720,12721,12723,12726,12728,12731,12733],{"class":1034,"line":1600},[1032,12722,1220],{"class":1042},[1032,12724,12725],{"class":1049},".flyweight ",[1032,12727,1226],{"class":1038},[1032,12729,12730],{"class":1049}," FlyWeightFactory.",[1032,12732,6919],{"class":1195},[1032,12734,12735],{"class":1049},"(make, model, processor);\n",[1032,12737,12738,12740,12743,12745],{"class":1034,"line":1615},[1032,12739,1220],{"class":1042},[1032,12741,12742],{"class":1049},".memory ",[1032,12744,1226],{"class":1038},[1032,12746,12747],{"class":1049}," memory;\n",[1032,12749,12750,12752,12755,12757],{"class":1034,"line":1631},[1032,12751,1220],{"class":1042},[1032,12753,12754],{"class":1049},".tag ",[1032,12756,1226],{"class":1038},[1032,12758,12759],{"class":1049}," tag;\n",[1032,12761,12762,12764,12766,12769,12771,12773],{"class":1034,"line":1642},[1032,12763,1220],{"class":1042},[1032,12765,1271],{"class":1049},[1032,12767,12768],{"class":1195},"getMake",[1032,12770,1046],{"class":1038},[1032,12772,7306],{"class":1038},[1032,12774,8622],{"class":1049},[1032,12776,12777,12779,12781],{"class":1034,"line":1648},[1032,12778,3220],{"class":1038},[1032,12780,1533],{"class":1042},[1032,12782,12783],{"class":1049},".flyweight.make;\n",[1032,12785,12786],{"class":1034,"line":1653},[1032,12787,9753],{"class":1049},[1032,12789,12790],{"class":1034,"line":1669},[1032,12791,1306],{"class":1049},[1032,12793,12794],{"class":1034,"line":1682},[1032,12795,1312],{"class":1049},[1032,12797,12798],{"class":1034,"line":1695},[1032,12799,1087],{"emptyLinePlaceholder":1086},[1032,12801,12802,12804,12807,12809,12811,12813],{"class":1034,"line":1705},[1032,12803,1039],{"class":1038},[1032,12805,12806],{"class":1042}," computers",[1032,12808,1046],{"class":1038},[1032,12810,1530],{"class":1038},[1032,12812,12558],{"class":1195},[1032,12814,1573],{"class":1049},[1032,12816,12817],{"class":1034,"line":1710},[1032,12818,1087],{"emptyLinePlaceholder":1086},[1032,12820,12821,12824,12826,12828,12830,12832,12835,12837,12840,12842,12845,12847,12850],{"class":1034,"line":1715},[1032,12822,12823],{"class":1049},"computers.",[1032,12825,6834],{"class":1195},[1032,12827,1207],{"class":1049},[1032,12829,5763],{"class":1059},[1032,12831,2819],{"class":1049},[1032,12833,12834],{"class":1059},"'MacBook Pro'",[1032,12836,2819],{"class":1049},[1032,12838,12839],{"class":1059},"'Intel'",[1032,12841,2819],{"class":1049},[1032,12843,12844],{"class":1059},"'5G'",[1032,12846,2819],{"class":1049},[1032,12848,12849],{"class":1059},"'Y755P'",[1032,12851,1743],{"class":1049},[1032,12853,12854,12856,12858,12860,12862,12864,12866,12868,12870,12872,12875,12877,12880],{"class":1034,"line":1722},[1032,12855,12823],{"class":1049},[1032,12857,6834],{"class":1195},[1032,12859,1207],{"class":1049},[1032,12861,5763],{"class":1059},[1032,12863,2819],{"class":1049},[1032,12865,12834],{"class":1059},[1032,12867,2819],{"class":1049},[1032,12869,12839],{"class":1059},[1032,12871,2819],{"class":1049},[1032,12873,12874],{"class":1059},"'6G'",[1032,12876,2819],{"class":1049},[1032,12878,12879],{"class":1059},"'X997T'",[1032,12881,1743],{"class":1049},[1032,12883,12884,12886,12888,12890,12892,12894,12896,12898,12900,12902,12905,12907,12910],{"class":1034,"line":1746},[1032,12885,12823],{"class":1049},[1032,12887,6834],{"class":1195},[1032,12889,1207],{"class":1049},[1032,12891,5763],{"class":1059},[1032,12893,2819],{"class":1049},[1032,12895,12834],{"class":1059},[1032,12897,2819],{"class":1049},[1032,12899,12839],{"class":1059},[1032,12901,2819],{"class":1049},[1032,12903,12904],{"class":1059},"'2G'",[1032,12906,2819],{"class":1049},[1032,12908,12909],{"class":1059},"'U8U80'",[1032,12911,1743],{"class":1049},[1032,12913,12914,12916,12918,12920,12922,12924,12926,12928,12930,12932,12934,12936,12939],{"class":1034,"line":1752},[1032,12915,12823],{"class":1049},[1032,12917,6834],{"class":1195},[1032,12919,1207],{"class":1049},[1032,12921,5763],{"class":1059},[1032,12923,2819],{"class":1049},[1032,12925,12834],{"class":1059},[1032,12927,2819],{"class":1049},[1032,12929,12839],{"class":1059},[1032,12931,2819],{"class":1049},[1032,12933,12904],{"class":1059},[1032,12935,2819],{"class":1049},[1032,12937,12938],{"class":1059},"'NT777'",[1032,12940,1743],{"class":1049},[1032,12942,12943,12945,12947,12949,12951,12953,12955,12957,12959,12961,12963,12965,12968],{"class":1034,"line":1762},[1032,12944,12823],{"class":1049},[1032,12946,6834],{"class":1195},[1032,12948,1207],{"class":1049},[1032,12950,5763],{"class":1059},[1032,12952,2819],{"class":1049},[1032,12954,12834],{"class":1059},[1032,12956,2819],{"class":1049},[1032,12958,12839],{"class":1059},[1032,12960,2819],{"class":1049},[1032,12962,12904],{"class":1059},[1032,12964,2819],{"class":1049},[1032,12966,12967],{"class":1059},"'0J88A'",[1032,12969,1743],{"class":1049},[1032,12971,12972,12974,12976,12978,12981,12983,12986,12988,12990,12992,12995,12997,13000],{"class":1034,"line":1767},[1032,12973,12823],{"class":1049},[1032,12975,6834],{"class":1195},[1032,12977,1207],{"class":1049},[1032,12979,12980],{"class":1059},"'HP'",[1032,12982,2819],{"class":1049},[1032,12984,12985],{"class":1059},"'Envy'",[1032,12987,2819],{"class":1049},[1032,12989,12839],{"class":1059},[1032,12991,2819],{"class":1049},[1032,12993,12994],{"class":1059},"'4G'",[1032,12996,2819],{"class":1049},[1032,12998,12999],{"class":1059},"'CNU883701'",[1032,13001,1743],{"class":1049},[1032,13003,13004,13006,13008,13010,13012,13014,13016,13018,13020,13022,13024,13026,13029],{"class":1034,"line":1787},[1032,13005,12823],{"class":1049},[1032,13007,6834],{"class":1195},[1032,13009,1207],{"class":1049},[1032,13011,12980],{"class":1059},[1032,13013,2819],{"class":1049},[1032,13015,12985],{"class":1059},[1032,13017,2819],{"class":1049},[1032,13019,12839],{"class":1059},[1032,13021,2819],{"class":1049},[1032,13023,12904],{"class":1059},[1032,13025,2819],{"class":1049},[1032,13027,13028],{"class":1059},"'TXU003283'",[1032,13030,1743],{"class":1049},[1032,13032,13033],{"class":1034,"line":1793},[1032,13034,1087],{"emptyLinePlaceholder":1086},[1032,13036,13037,13039,13041,13043,13046,13048,13051,13054],{"class":1034,"line":4312},[1032,13038,1725],{"class":1049},[1032,13040,1728],{"class":1195},[1032,13042,1207],{"class":1049},[1032,13044,13045],{"class":1059},"'Computers: '",[1032,13047,5429],{"class":1038},[1032,13049,13050],{"class":1049}," computers.",[1032,13052,13053],{"class":1195},"getCount",[1032,13055,2728],{"class":1049},[1032,13057,13058,13060,13062,13064,13067,13069,13071,13073],{"class":1034,"line":4323},[1032,13059,1725],{"class":1049},[1032,13061,1728],{"class":1195},[1032,13063,1207],{"class":1049},[1032,13065,13066],{"class":1059},"'Flyweights: '",[1032,13068,5429],{"class":1038},[1032,13070,12730],{"class":1049},[1032,13072,13053],{"class":1195},[1032,13074,2728],{"class":1049},[927,13076,13077],{},"In the above example code, we are building computers. Many models, makes, and processor combinations are common, so these characteristics are factored out and shared by Flyweight objects.",[994,13079,13081],{"id":13080},"proxy","Proxy",[927,13083,2741,13084,13088],{},[967,13085,13086],{},[930,13087,13081],{}," pattern is a structural design pattern. A proxy, in its most general form, is a class functioning as an interface to something else.",[927,13090,13091],{},[948,13092],{"alt":13081,"src":13093},"\u002Fimages\u002Fblog\u002F2021-12-16-javascript-design-patterns\u002Fproxy.png",[927,13095,2138,13096,13100],{},[967,13097,13098],{},[930,13099,13081],{}," pattern provides a surrogate or placeholder object for another object and controls access to this other object.",[1022,13102,13104],{"className":1024,"code":13103,"language":1026,"meta":1027,"style":1027},"class GeoCoder {\n  getLatLng(address) {\n    if (address === 'Amsterdam') {\n      return '52.3700° N, 4.8900° E';\n    } else if (address === 'London') {\n      return '51.5171° N, 0.1062° W';\n    } else if (address === 'Paris') {\n      return '48.8742° N, 2.3470° E';\n    } else if (address === 'Berlin') {\n      return '52.5233° N, 13.4127° E';\n    } else {\n      return '';\n    }\n  }\n}\n\nclass GeoProxy {\n  constructor() {\n    const geocoder = new GeoCoder();\n    const geocache = {};\n\n    return {\n      getLatLng: function (address) {\n        if (!geocache[address]) {\n          geocache[address] = geocoder.getLatLng(address);\n        }\n        console.log(address + ': ' + geocache[address]);\n        return geocache[address];\n      },\n      getCount: function () {\n        const count = 0;\n        for (let code in geocache) {\n          count++;\n        }\n        return count;\n      },\n    };\n  }\n}\n\nconst geo = new GeoProxy();\n\n\u002F\u002F geolocation requests\ngeo.getLatLng('Paris');\ngeo.getLatLng('London');\ngeo.getLatLng('London');\ngeo.getLatLng('London');\ngeo.getLatLng('London');\ngeo.getLatLng('Amsterdam');\ngeo.getLatLng('Amsterdam');\ngeo.getLatLng('Amsterdam');\ngeo.getLatLng('Amsterdam');\ngeo.getLatLng('London');\ngeo.getLatLng('London');\n\nconsole.log('\\nCache size: ' + geo.getCount());\n",[1029,13105,13106,13115,13127,13141,13150,13167,13176,13193,13202,13219,13228,13236,13244,13248,13252,13256,13260,13269,13275,13290,13301,13305,13311,13326,13337,13353,13357,13376,13383,13387,13398,13411,13428,13437,13441,13447,13451,13455,13459,13463,13467,13482,13486,13491,13505,13518,13530,13542,13554,13567,13579,13591,13603,13615,13627,13631],{"__ignoreMap":1027},[1032,13107,13108,13110,13113],{"class":1034,"line":1035},[1032,13109,1192],{"class":1038},[1032,13111,13112],{"class":1195}," GeoCoder",[1032,13114,1050],{"class":1049},[1032,13116,13117,13120,13122,13125],{"class":1034,"line":1053},[1032,13118,13119],{"class":1195},"  getLatLng",[1032,13121,1207],{"class":1049},[1032,13123,13124],{"class":1210},"address",[1032,13126,1214],{"class":1049},[1032,13128,13129,13131,13134,13136,13139],{"class":1034,"line":1066},[1032,13130,3212],{"class":1038},[1032,13132,13133],{"class":1049}," (address ",[1032,13135,1734],{"class":1038},[1032,13137,13138],{"class":1059}," 'Amsterdam'",[1032,13140,1214],{"class":1049},[1032,13142,13143,13145,13148],{"class":1034,"line":1077},[1032,13144,3220],{"class":1038},[1032,13146,13147],{"class":1059}," '52.3700° N, 4.8900° E'",[1032,13149,1251],{"class":1049},[1032,13151,13152,13154,13156,13158,13160,13162,13165],{"class":1034,"line":1083},[1032,13153,4903],{"class":1049},[1032,13155,4906],{"class":1038},[1032,13157,4909],{"class":1038},[1032,13159,13133],{"class":1049},[1032,13161,1734],{"class":1038},[1032,13163,13164],{"class":1059}," 'London'",[1032,13166,1214],{"class":1049},[1032,13168,13169,13171,13174],{"class":1034,"line":1090},[1032,13170,3220],{"class":1038},[1032,13172,13173],{"class":1059}," '51.5171° N, 0.1062° W'",[1032,13175,1251],{"class":1049},[1032,13177,13178,13180,13182,13184,13186,13188,13191],{"class":1034,"line":1102},[1032,13179,4903],{"class":1049},[1032,13181,4906],{"class":1038},[1032,13183,4909],{"class":1038},[1032,13185,13133],{"class":1049},[1032,13187,1734],{"class":1038},[1032,13189,13190],{"class":1059}," 'Paris'",[1032,13192,1214],{"class":1049},[1032,13194,13195,13197,13200],{"class":1034,"line":1113},[1032,13196,3220],{"class":1038},[1032,13198,13199],{"class":1059}," '48.8742° N, 2.3470° E'",[1032,13201,1251],{"class":1049},[1032,13203,13204,13206,13208,13210,13212,13214,13217],{"class":1034,"line":1124},[1032,13205,4903],{"class":1049},[1032,13207,4906],{"class":1038},[1032,13209,4909],{"class":1038},[1032,13211,13133],{"class":1049},[1032,13213,1734],{"class":1038},[1032,13215,13216],{"class":1059}," 'Berlin'",[1032,13218,1214],{"class":1049},[1032,13220,13221,13223,13226],{"class":1034,"line":1135},[1032,13222,3220],{"class":1038},[1032,13224,13225],{"class":1059}," '52.5233° N, 13.4127° E'",[1032,13227,1251],{"class":1049},[1032,13229,13230,13232,13234],{"class":1034,"line":1140},[1032,13231,4903],{"class":1049},[1032,13233,4906],{"class":1038},[1032,13235,1050],{"class":1049},[1032,13237,13238,13240,13242],{"class":1034,"line":1145},[1032,13239,3220],{"class":1038},[1032,13241,7973],{"class":1059},[1032,13243,1251],{"class":1049},[1032,13245,13246],{"class":1034,"line":1157},[1032,13247,1516],{"class":1049},[1032,13249,13250],{"class":1034,"line":1168},[1032,13251,1306],{"class":1049},[1032,13253,13254],{"class":1034,"line":1179},[1032,13255,1312],{"class":1049},[1032,13257,13258],{"class":1034,"line":1184},[1032,13259,1087],{"emptyLinePlaceholder":1086},[1032,13261,13262,13264,13267],{"class":1034,"line":1189},[1032,13263,1192],{"class":1038},[1032,13265,13266],{"class":1195}," GeoProxy",[1032,13268,1050],{"class":1049},[1032,13270,13271,13273],{"class":1034,"line":1201},[1032,13272,1204],{"class":1038},[1032,13274,1868],{"class":1049},[1032,13276,13277,13279,13282,13284,13286,13288],{"class":1034,"line":1217},[1032,13278,3192],{"class":1038},[1032,13280,13281],{"class":1042}," geocoder",[1032,13283,1046],{"class":1038},[1032,13285,1530],{"class":1038},[1032,13287,13112],{"class":1195},[1032,13289,1573],{"class":1049},[1032,13291,13292,13294,13297,13299],{"class":1034,"line":1232},[1032,13293,3192],{"class":1038},[1032,13295,13296],{"class":1042}," geocache",[1032,13298,1046],{"class":1038},[1032,13300,6065],{"class":1049},[1032,13302,13303],{"class":1034,"line":1254},[1032,13304,1087],{"emptyLinePlaceholder":1086},[1032,13306,13307,13309],{"class":1034,"line":1279},[1032,13308,1527],{"class":1038},[1032,13310,1050],{"class":1049},[1032,13312,13313,13316,13318,13320,13322,13324],{"class":1034,"line":1303},[1032,13314,13315],{"class":1195},"      getLatLng",[1032,13317,9695],{"class":1049},[1032,13319,5812],{"class":1038},[1032,13321,5359],{"class":1049},[1032,13323,13124],{"class":1210},[1032,13325,1214],{"class":1049},[1032,13327,13328,13330,13332,13334],{"class":1034,"line":1309},[1032,13329,6195],{"class":1038},[1032,13331,5359],{"class":1049},[1032,13333,12412],{"class":1038},[1032,13335,13336],{"class":1049},"geocache[address]) {\n",[1032,13338,13339,13342,13344,13347,13350],{"class":1034,"line":1315},[1032,13340,13341],{"class":1049},"          geocache[address] ",[1032,13343,1226],{"class":1038},[1032,13345,13346],{"class":1049}," geocoder.",[1032,13348,13349],{"class":1195},"getLatLng",[1032,13351,13352],{"class":1049},"(address);\n",[1032,13354,13355],{"class":1034,"line":1320},[1032,13356,6225],{"class":1049},[1032,13358,13359,13362,13364,13367,13369,13371,13373],{"class":1034,"line":1330},[1032,13360,13361],{"class":1049},"        console.",[1032,13363,1728],{"class":1195},[1032,13365,13366],{"class":1049},"(address ",[1032,13368,3910],{"class":1038},[1032,13370,6021],{"class":1059},[1032,13372,5429],{"class":1038},[1032,13374,13375],{"class":1049}," geocache[address]);\n",[1032,13377,13378,13380],{"class":1034,"line":1341},[1032,13379,7190],{"class":1038},[1032,13381,13382],{"class":1049}," geocache[address];\n",[1032,13384,13385],{"class":1034,"line":1352},[1032,13386,9748],{"class":1049},[1032,13388,13389,13392,13394,13396],{"class":1034,"line":1374},[1032,13390,13391],{"class":1195},"      getCount",[1032,13393,9695],{"class":1049},[1032,13395,5812],{"class":1038},[1032,13397,8622],{"class":1049},[1032,13399,13400,13403,13405,13407,13409],{"class":1034,"line":1396},[1032,13401,13402],{"class":1038},"        const",[1032,13404,3512],{"class":1042},[1032,13406,1046],{"class":1038},[1032,13408,3756],{"class":1042},[1032,13410,1251],{"class":1049},[1032,13412,13413,13416,13418,13420,13423,13425],{"class":1034,"line":1401},[1032,13414,13415],{"class":1038},"        for",[1032,13417,5359],{"class":1049},[1032,13419,5362],{"class":1038},[1032,13421,13422],{"class":1049}," code ",[1032,13424,12509],{"class":1038},[1032,13426,13427],{"class":1049}," geocache) {\n",[1032,13429,13430,13433,13435],{"class":1034,"line":1406},[1032,13431,13432],{"class":1049},"          count",[1032,13434,5391],{"class":1038},[1032,13436,1251],{"class":1049},[1032,13438,13439],{"class":1034,"line":1411},[1032,13440,6225],{"class":1049},[1032,13442,13443,13445],{"class":1034,"line":1421},[1032,13444,7190],{"class":1038},[1032,13446,12672],{"class":1049},[1032,13448,13449],{"class":1034,"line":1433},[1032,13450,9748],{"class":1049},[1032,13452,13453],{"class":1034,"line":1442},[1032,13454,9753],{"class":1049},[1032,13456,13457],{"class":1034,"line":1458},[1032,13458,1306],{"class":1049},[1032,13460,13461],{"class":1034,"line":1472},[1032,13462,1312],{"class":1049},[1032,13464,13465],{"class":1034,"line":1480},[1032,13466,1087],{"emptyLinePlaceholder":1086},[1032,13468,13469,13471,13474,13476,13478,13480],{"class":1034,"line":1494},[1032,13470,1039],{"class":1038},[1032,13472,13473],{"class":1042}," geo",[1032,13475,1046],{"class":1038},[1032,13477,1530],{"class":1038},[1032,13479,13266],{"class":1195},[1032,13481,1573],{"class":1049},[1032,13483,13484],{"class":1034,"line":1506},[1032,13485,1087],{"emptyLinePlaceholder":1086},[1032,13487,13488],{"class":1034,"line":1513},[1032,13489,13490],{"class":1718},"\u002F\u002F geolocation requests\n",[1032,13492,13493,13496,13498,13500,13503],{"class":1034,"line":1519},[1032,13494,13495],{"class":1049},"geo.",[1032,13497,13349],{"class":1195},[1032,13499,1207],{"class":1049},[1032,13501,13502],{"class":1059},"'Paris'",[1032,13504,1743],{"class":1049},[1032,13506,13507,13509,13511,13513,13516],{"class":1034,"line":1524},[1032,13508,13495],{"class":1049},[1032,13510,13349],{"class":1195},[1032,13512,1207],{"class":1049},[1032,13514,13515],{"class":1059},"'London'",[1032,13517,1743],{"class":1049},[1032,13519,13520,13522,13524,13526,13528],{"class":1034,"line":1544},[1032,13521,13495],{"class":1049},[1032,13523,13349],{"class":1195},[1032,13525,1207],{"class":1049},[1032,13527,13515],{"class":1059},[1032,13529,1743],{"class":1049},[1032,13531,13532,13534,13536,13538,13540],{"class":1034,"line":1549},[1032,13533,13495],{"class":1049},[1032,13535,13349],{"class":1195},[1032,13537,1207],{"class":1049},[1032,13539,13515],{"class":1059},[1032,13541,1743],{"class":1049},[1032,13543,13544,13546,13548,13550,13552],{"class":1034,"line":1554},[1032,13545,13495],{"class":1049},[1032,13547,13349],{"class":1195},[1032,13549,1207],{"class":1049},[1032,13551,13515],{"class":1059},[1032,13553,1743],{"class":1049},[1032,13555,13556,13558,13560,13562,13565],{"class":1034,"line":1559},[1032,13557,13495],{"class":1049},[1032,13559,13349],{"class":1195},[1032,13561,1207],{"class":1049},[1032,13563,13564],{"class":1059},"'Amsterdam'",[1032,13566,1743],{"class":1049},[1032,13568,13569,13571,13573,13575,13577],{"class":1034,"line":1576},[1032,13570,13495],{"class":1049},[1032,13572,13349],{"class":1195},[1032,13574,1207],{"class":1049},[1032,13576,13564],{"class":1059},[1032,13578,1743],{"class":1049},[1032,13580,13581,13583,13585,13587,13589],{"class":1034,"line":1581},[1032,13582,13495],{"class":1049},[1032,13584,13349],{"class":1195},[1032,13586,1207],{"class":1049},[1032,13588,13564],{"class":1059},[1032,13590,1743],{"class":1049},[1032,13592,13593,13595,13597,13599,13601],{"class":1034,"line":1600},[1032,13594,13495],{"class":1049},[1032,13596,13349],{"class":1195},[1032,13598,1207],{"class":1049},[1032,13600,13564],{"class":1059},[1032,13602,1743],{"class":1049},[1032,13604,13605,13607,13609,13611,13613],{"class":1034,"line":1615},[1032,13606,13495],{"class":1049},[1032,13608,13349],{"class":1195},[1032,13610,1207],{"class":1049},[1032,13612,13515],{"class":1059},[1032,13614,1743],{"class":1049},[1032,13616,13617,13619,13621,13623,13625],{"class":1034,"line":1631},[1032,13618,13495],{"class":1049},[1032,13620,13349],{"class":1195},[1032,13622,1207],{"class":1049},[1032,13624,13515],{"class":1059},[1032,13626,1743],{"class":1049},[1032,13628,13629],{"class":1034,"line":1642},[1032,13630,1087],{"emptyLinePlaceholder":1086},[1032,13632,13633,13635,13637,13639,13642,13644,13647,13649,13652,13654],{"class":1034,"line":1648},[1032,13634,1725],{"class":1049},[1032,13636,1728],{"class":1195},[1032,13638,1207],{"class":1049},[1032,13640,13641],{"class":1059},"'",[1032,13643,3480],{"class":1042},[1032,13645,13646],{"class":1059},"Cache size: '",[1032,13648,5429],{"class":1038},[1032,13650,13651],{"class":1049}," geo.",[1032,13653,13053],{"class":1195},[1032,13655,2728],{"class":1049},[953,13657,13659],{"id":13658},"summary","Summary",[927,13661,13662],{},"Design patterns represent some of the best practices adopted by experienced object-oriented software developers. They are time-tested solutions for various software design problems.",[927,13664,13665,13666,1271],{},"The repository for all the code snippets can be found ",[13667,13668,13672],"a",{"href":13669,"rel":13670},"https:\u002F\u002Fgithub.com\u002Fszaranger\u002Fjavascript-design-patterns",[13671],"nofollow","here",[927,13674,13675],{},"In this article, we have explored common creational design patterns in JavaScript including the following:",[927,13677,13678],{},"Factory Method\nAbstract Factory\nBuilder\nPrototype\nSingleton\nChain of responsibility\nCommand\nInterpreter\nIterator\nMediator\nMemento\nObserver\nState\nStrategy\nTemplate Method\nVisitor\nAdapter\nBridge\nComposite\nDecorator\nFaçade\nFlyweight\nProxy",[13680,13681,13682],"style",{},"html pre.shiki code .szBVR, html code.shiki .szBVR{--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sj4cs, html code.shiki .sj4cs{--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sVt8B, html code.shiki .sVt8B{--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sZZnC, html code.shiki .sZZnC{--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .sScJk, html code.shiki .sScJk{--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .s4XuR, html code.shiki .s4XuR{--shiki-default:#E36209;--shiki-dark:#FFAB70}html pre.shiki code .sJ8bj, html code.shiki .sJ8bj{--shiki-default:#6A737D;--shiki-dark:#6A737D}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":1027,"searchDepth":1053,"depth":1053,"links":13684},[13685,13686,13693,13694,13695,13696,13697,13698,13699,13700,13701,13702,13703,13704,13705,13714],{"id":955,"depth":1053,"text":956},{"id":991,"depth":1053,"text":992,"children":13687},[13688,13689,13690,13691,13692],{"id":996,"depth":1066,"text":997},{"id":1806,"depth":1066,"text":1807},{"id":2134,"depth":1066,"text":2135},{"id":2737,"depth":1066,"text":2738},{"id":3111,"depth":1066,"text":3112},{"id":3399,"depth":1053,"text":992},{"id":3405,"depth":1053,"text":3406},{"id":3679,"depth":1053,"text":3680},{"id":4607,"depth":1053,"text":4608},{"id":5441,"depth":1053,"text":5442},{"id":5850,"depth":1053,"text":5851},{"id":6451,"depth":1053,"text":6452},{"id":6969,"depth":1053,"text":6970},{"id":7438,"depth":1053,"text":7439},{"id":7918,"depth":1053,"text":7919},{"id":8460,"depth":1053,"text":8461},{"id":8724,"depth":1053,"text":8725},{"id":9361,"depth":1053,"text":9362,"children":13706},[13707,13708,13709,13710,13711,13712,13713],{"id":9365,"depth":1066,"text":9366},{"id":9946,"depth":1066,"text":9947},{"id":10667,"depth":1066,"text":10668},{"id":11325,"depth":1066,"text":11326},{"id":11665,"depth":1066,"text":11668},{"id":12246,"depth":1066,"text":12249},{"id":13080,"depth":1066,"text":13081},{"id":13658,"depth":1053,"text":13659},"2021-12-16","md","\u002Fimages\u002Fblog\u002Ffeatures\u002Fjavascript-design-patterns.jpg",{},{"title":516,"description":518},"blog\u002Fjavascript-design-patterns",[16,17,520],"JBdXOfhgp6kVrtVFFAVVSzUHAU9pE5N4FxwGZyVYcEg",[13724,13726],{"title":855,"path":856,"stem":13725,"children":-1},"blog\u002Fturborepo-the-next-big-thing-in-build-systems",{"title":421,"path":422,"stem":13727,"children":-1},"blog\u002Fimproving-next-js-performance",1784954516153]