ES6 & tagged-template-literals & template strings
ES6 & tagged-template-literals & template strings
tagged template
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#Tagged_templates
demo
https://wesbos.com/tagged-template-literals/
function highlight(strings, ...values) {
let str = '';
strings.forEach((string, i) => {
str += string + (values[i] || ``);
});
return str;
}
const name = 'Snickers';
const age = '100';
const sentence = highlight`My dog's name is ${name} and he is ${age} years old`;
console.log(sentence);
// My dog's name is Snickers and he is 100 years old

tagged-template-literals
https://www.leighhalliday.com/tagged-template-literals
https://www.freecodecamp.org/news/es6-tagged-template-literals-48a70ef3ed4d/
https://www.freecodecamp.org/news/a-quick-introduction-to-tagged-template-literals-2a07fd54bc1d/
https://dev.to/sarah_chima/tagged-template-literals-2ho
https://exploringjs.com/impatient-js/ch_template-literals.html#tagged-templates
demo
https://github.com/mqyqingfeng/Blog/issues/84

let x = 'Hi', y = 'Kevin';
const res = message`${x}, I am ${y}`;
console.log(res);
// 我们可以自定义 message 函数来处理返回的字符串:
// literals 文字
// 注意在这个例子中 literals 的第一个元素和最后一个元素都是空字符串
function message(literals, value1, value2) {
console.log(literals); // [ "", ", I am ", "" ]
console.log(value1); // Hi
console.log(value2); // Kevin
}
React & styled-components
https://www.styled-components.com/
https://github.com/styled-components/styled-components
const Button = styled.a`
/* This renders the buttons above... Edit me! */
display: inline-block;
border-radius: 3px;
padding: 0.5rem 0;
margin: 0.5rem 1rem;
width: 11rem;
background: transparent;
color: white;
border: 2px solid white;
/* The GitHub button is a primary button
* edit this to target it specifically! */
${props => props.primary && css`
background: white;
color: palevioletred;
`}
`;
demo
"use strict";
/**
*
* @author xgqfrms
* @license MIT
* @copyright xgqfrms
* @created 2019-08-16
*
* @description tagged-template-literals
* @augments
* @example
* @link https://github.com/lydiahallie/javascript-questions#17-whats-the-output
*
*/
let log = console.log;
function getPersonInfo(one, two, three) {
log(one);
log(two);
log(three);
}
const person = "xgqfrms";
const age = 23;
getPersonInfo`${person} is ${age} years old`;
// [ '', ' is ', ' years old' ]
// xgqfrms
// 23
xgqfrms 2012-2020
www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!
ES6 & tagged-template-literals & template strings的更多相关文章
- Template literals
[Template literals] Template literals are string literals allowing embedded expressions. You can use ...
- Django.template框架 template context (非常详细)
前面的章节我们看到如何在视图中返回HTML,但是HTML是硬编码在Python代码中的 这会导致几个问题: 1,显然,任何页面的改动会牵扯到Python代码的改动 网站的设计改动会比Python代码改 ...
- Package template (html/template) ... Types HTML, JS, URL, and others from content.go can carry safe content that is exempted from escaping. ... (*Template) Funcs ..
https://godoc.org/text/template GoDoc Home About Go: text/templateIndex | Examples | Files | Directo ...
- Error resolving template [xxx], template might not exist or might not be exist
Springboot+thymeleaf+mybatis 抛Error resolving template [xxx], template might not exist的异常 原因是我们在pom. ...
- Error resolving template: template might not exist or might not be accessible是一句缩水报错?
一 thymeleaf在开发的时候本地调试正常,但是在测试环境打成jar包就报这个错误了. 二 template might not exist or might not be accessible ...
- 【报错】An error happened during template parsing (template: "class path resource [templates/adminManageCourse.html]")
页面显示: Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing t ...
- 【报错】An error happened during template parsing (template: "class path resource [templates/hello1.html]")
页面显示: Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing t ...
- Thymeleaf 异常:Exception processing template "index": An error happened during template parsing (template: "class path resource [templates/index.html]")
Spring Boot 项目,在 Spring Tool Suite 4, Version: 4.4.0.RELEASE 运行没有问题,将项目中的静态资源和页面复制到 IDEA 的项目中,除了 IDE ...
- ES6 Features系列:Template Strings & Tagged Template Strings
1. Brief ES6(ECMAScript 6th edition)于2015年7月份发布,虽然各大浏览器仍未全面支持ES6,但我们可以在后端通过Node.js 0.12和io.js,而前端则通过 ...
- 异常:Error resolving template "xxx", template might not exist or might not be accessible...解决办法
在开发环境下正常,但使用jar运行时,报错Error resolving template template might not exist or might not be accessible,意思 ...
随机推荐
- 【LinuxShell】echo用法详解
使用echo打印信息到终端 1 [Shell]echo "yz test" 2 yz test 3 [Shell]echo yz test 4 yz test 5 [Shell]e ...
- LOJ10068 秘密的牛奶运输
LOJ10068秘密的牛奶运输 题目描述 Farmer John 要把他的牛奶运输到各个销售点.运输过程中,可以先把牛奶运输到一些销售点,再由这些销售点分别运输到其他销售点. 运输的总距离越小,运输的 ...
- IO多路复用与epoll机制浅析
epoll是Linux中用于IO多路复用的机制,在nginx和redis等软件中都有应用,redis的性能好的原因之一也就是使用了epoll进行IO多路复用,同时epoll也是各大公司面试的热点问题. ...
- Java执行Dos-Shell脚本
Java执行Dos-Shell脚本 1.介绍 2.调用shell脚本 2.1 获取键盘输入 2.2 构建指令 2.3 Java代码 3.Java调用Shell并传入参数 4.Java调用远程的Shel ...
- Java——Math,Set,List,map相关练习
声明一个Set集合,只能保存Double类型的数据, 保存10个随机100以内的数, 找出最大值和最小值,打印输出. public static void main(String[] args) { ...
- typedef void (*sighandler_t)(int);
typedef void (*sighandler_t)(int); sighandler_t signal(int signum, sighandler_t handler); ---------- ...
- 弱网测试之Fidder
是用Fidder可以模拟若罔测试. 1.Fiider设置 fiddler中选中Rules->Cutomize Rules,在文件中搜索关键字:m_SimulateModem: 修改m_Simul ...
- 设计模式(五)——原型模式(加Spring框架源码分析)
原型模式 1 克隆羊问题 现在有一只羊 tom,姓名为: tom, 年龄为:1,颜色为:白色,请编写程序创建和 tom 羊 属性完全相同的 10 只羊. 2 传统方式解决克隆羊问题 1) 思路分析(图 ...
- 2014-2015 ACM-ICPC, NEERC, Southern Subregional Contest 题解(PART)(9/13)
$$2014-2015\ ACM-ICPC,\ NEERC,\ Southern\ Subregional\ Contest$$ A Nasta Rabbara B Colored Blankets ...
- zjnu1707 TOPOVI (map+模拟)
Description Mirko is a huge fan of chess and programming, but typical chess soon became boring for h ...