Skip to content

ch02: fix typos in tagged templates examples #58

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 4, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
ch02: fix typos in tagged templates examples
  • Loading branch information
vsemozhetbyt committed Apr 3, 2018
commit 5026396667815b7e0a04def60c51a93e60a7338f
4 changes: 2 additions & 2 deletions ch02.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,7 @@ var name = 'Maurice'
var emotion = 'thrilled'
var text = tag`Hello, ${ name }. I am ${ emotion } to meet you!`
console.log(text)
// <- 'Hello Maurice, I am thrilled to meet you!'
// <- 'Hello, Maurice. I am thrilled to meet you!'
----

Multiple use cases apply to tagged templates. One possible use case might be to make user input uppercase, making the string sound satirical. That's what the following piece of code does. We've modified `tag` slightly so that any interpolated strings are uppercased.
Expand All @@ -1200,7 +1200,7 @@ function upper(parts, ...values) {
var name = 'Maurice'
var emotion = 'thrilled'
upper`Hello, ${ name }. I am ${ emotion } to meet you!`
// <- 'Hello MAURICE, I am THRILLED to meet you!'
// <- 'Hello, MAURICE. I am THRILLED to meet you!'
----

A decidedly more useful use case would be to sanitize expressions interpolated into your templates, automatically, using a tagged template. Given a template where all expressions are considered user input, we could use a hypothetical `sanitize` library to remove HTML tags and similar hazards, preventing cross-site scripting (XSS) attacks where users might inject malicious HTML into our websites.
Expand Down