At a high level, this week is about learning to write a frontend, single page app using only pure JavaScript.
In this workshop, you'll practice one part of this: encapsulating and sharing your modules in an idiomatic way.
- Describe the module pattern as a way to encapsulate and share code.
- Explain how the module pattern makes some code available and hides other code.
- Write code using the module pattern.
-
Pair up.
-
Clone this repo.
-
Open
SpecRunner.htmlin your browser to run the tests. -
TDD a
smiley.jsmodule. It should have a function that takes some text and returns the text with a space and a smiley appended. e.g.smiley("hello")should return"hello :)". -
Rename
interrobang.jstointerrobangsmiley.js. Update the code to use yoursmiley.jsfunction to include a smiley in its output. For example:hello??! :). -
Try and answer the questions below.
-
How does the function that wraps the question module keep
QUESTION_MARK_COUNTprivate? Why is this useful? -
How does the pattern used in the
questionandexclaimmodules differ from the pattern used in theinterrobangmodule? Why are different patterns used? -
Can you predict and confirm the value of
thisin all the parts of each module?
We'll come back together for a short plenary. We'll discuss problems we had writing code that uses the module pattern. And we'll answer the questions below.