Skip to content

Commit

Permalink
Improve example in Tagged template literals (mbeaudru#58)
Browse files Browse the repository at this point in the history
You don't need tagged template literals for wrapping text into <mark>.
  • Loading branch information
vrana authored and mbeaudru committed Oct 8, 2017
1 parent 017aa82 commit 13ef80c
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -1045,18 +1045,18 @@ Template tags are *functions that can be prefixed to a [template literal](#templ
Below is a toy example on they work.
```js
function highlight(strings, ...values) {
const interpolation = strings.reduce((prev, next) => {
return prev + next + (values.shift() || "");
const interpolation = strings.reduce((prev, current) => {
return prev + current + (values.length ? "<mark>" + values.shift() + "</mark>" : "");
}, "");

return `<mark>${interpolation}</mark>`;
return interpolation;
}

const condiment = "jam";
const meal = "toast";

highlight`I like ${condiment} on ${meal}.`;
// "<mark>I like jam on toast.</mark>"
// "I like <mark>jam</mark> on <mark>toast</mark>."
```

A more interesting example:
Expand Down

0 comments on commit 13ef80c

Please sign in to comment.