Modifying and extending patterns doesn't mean that we must forge ahead into terra incognita. It is still advisable to use well-known patterns when tackling new problems.
In this recipe, we'll see how to combine two patterns to better fit a given use case.
This recipe assumes you already have a workspace that allows you to create and run ES modules in your browser. If you don't, please see the first two chapters.
- Open your command-line application and navigate to your workspace.
- Create a new folder named
09-07-combine-design-patters-to-fit-new-use-case
. - Copy or create an
index.html
that loads and runs amain
function frommain.js
. - Create a
main.js
file that defines a newclass
namedMission
. Create a constructor that assigns aname
argument to an instance variable. Add a simpleprint
function:
// main.js class Mission { constructor (name) { this.name = name; } describe () { console.log...