xgqfrms / ES6

:sunny: ECMAScript 6(ES 6/ES 2015): New Features Overview & Comparison :fire:
https://es6.xgqfrms.xyz
MIT License
1 stars 5 forks source link

Tagged Template Literals & ES6 Template Literals/ ES6 Template Strings #5

Open xgqfrms opened 6 years ago

xgqfrms commented 6 years ago

Tagged Template Literals & ES6 Template Literals/ ES6 Template Strings

ES6 Template Strings & Tags


"use strict";

/**
 *
 * @author xgqfrms
 * @license MIT
 * @copyright
 * @description Tagged Template Literals &  ES6 Template Literals/ ES6 Template Strings
 * @augments
 * @example
 * @param {*} strings
 * @param {*} name
 * @param {*} age
 *
 */

const highlight = (strings, name, age) => {
    return `
        <div>
            <p>
                ${strings[0]}: <span style="color: #0f0; background: #000;">${name}</span>,
                ${strings[1]}: <span style="color: #0f0; background: #000;">${age}</span>,
                ${strings[2]}.
            </p>
        </div>
    `;
};

let name = "xgqfrms",
    age = 23,
    sentence = highlight`My name is ${name} and ${age} years old.`;
console.log(sentence);

const body = document.querySelector("body");
body.innerHTML = "";
body.insertAdjacentHTML("beforeend", sentence);

image

xgqfrms commented 6 years ago

"use strict";

/**
 *
 * @author xgqfrms
 * @license MIT
 * @copyright  xgqfrms
 * @description Tagged Template Literals &  ES6 Template Literals/ ES6 Template Strings
 * @augments ES6 Template Strings & Tags
 * @example ...
 * @param {*} strings
 * @param {*} name
 * @param {*} age
 * @reference https://wesbos.com/tagged-template-literals/
 *
 */

const highlight = (strings, name, age) => {
    return `
        <div>
            <p>
                ${strings[0]}: <span style="color: #0f0; background: #000;">${name}</span>,
                ${strings[1]}: <span style="color: #0f0; background: #000;">${age}</span>,
                ${strings[2]}.
            </p>
        </div>
    `;
};

let name = "xgqfrms",
    age = 23,
    sentence = highlight`My name is ${name} and ${age} years old.`;
console.log(sentence);

const body = document.querySelector("body");
body.innerHTML = "";
body.insertAdjacentHTML("beforeend", sentence);