Hướng dẫn dùng bash backtick trong PHP
ECMAScript 6 comes up with a new type of string literal, using the backtick as the delimiter. These literals do allow basic string interpolation expressions to be embedded, which are then automatically parsed and evaluated.
As you can see, we used the One really nice benefit of interpolated string literals is they are allowed to split across multiple lines:
Interpolated Expressions Any valid expression is allowed to appear inside
Here, the inner
Using the template literal for the HTML is definitely more readable by reducing the annoyance. The plain old way:
With ECMAScript 6:
Tagged Template Literals We can also tag a template string, when a template string is tagged, the literals and substitutions are passed to function which returns the resulting value.
We can use the spread operator here to pass multiple values. The first argument—we called it strings—is an array of all the plain strings (the stuff between any interpolated expressions). We then gather up all subsequent arguments into an
array called values using the
The argument(s) gathered into our values array are the results of the already evaluated interpolation expressions found in the string literal. A tagged string literal is like a processing step after the interpolations are evaluated, but before the final string value is compiled, allowing you more control over generating the string from the literal. Let's look at an example of creating reusable templates.
Raw Strings Our tag functions receive a first argument we called strings, which is an array. But there’s an additional bit of data included: the raw unprocessed versions of all the strings. You can access those raw string values using the
As you can see, the raw version of the string preserves the escaped
|