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,意思 ...
随机推荐
- Solon rpc 1.3.1 发布,推出Cloud接口与配置规范
Solon 是一个微型的Java RPC开发框架.项目从2018年启动以来,参考过大量前人作品:历时两年,3500多次的commit:内核保持0.1m的身材,超高的跑分,良好的使用体验.支持:Rpc. ...
- CF1433F Zero Remainder Sum
写在前面 思维难度不是很大的 DP,代码实现也很容易. 状态设计模式很套路,转移也很好理解. 算法思路 (因为 \(k\) 是常用的循环变量,下文中将题面中的模数改为 \(p\)) 虽然要求的是模 \ ...
- 某商城系统(V1.3-2020-01-10)前台命令执行漏洞
漏洞文件: ./inc/module/upload_img.php 先跟进 del_file 函数: 在 del_file 函数中首先执行了unlink操作,然后接着进行了file_exists 判断 ...
- windows下hash抓取的几种方式
前提:在渗透测试过程中,对于windows系统的机器渗透需要注意hash的获取,其中hash分为LM-HASH与NTLM-HASH,在windows系统中,hash的默认存储位置为: C:\Windo ...
- $().arr使用
$("#handmoney").attr("readonly","readonly"); 只读 $("img").att ...
- 2019牛客暑期多校训练营(第六场)D-Move
>传送门< 题意: 你有n件行李,有k个箱子体积相同的箱子,遵循下面的规则将行李放进箱子里面 每次都取当前最大的可以放进箱子的行李放进箱子,如果该箱子放不进任何行李那么就换一个新的箱子再按 ...
- HDU2065 "红色病毒"问题 【组合数学 二项式定理】
HDU2065 "红色病毒"问题 Description: 医学界发现的新病毒因其蔓延速度和Internet上传播的"红色病毒"不相上下,被称为"红色 ...
- 矩阵树定理(Kirchhoff || Laplace)初探——Part 1(无向图计数)
必备知识: 高斯消元,图论基本知识(好像就这...(雾)) 这里是无向图部分,请不要走错场... 定义 我们将邻接矩阵定义为矩阵\(A(u,v)\),我想邻接矩阵就不用再多说了: 我们将每个点的度数矩 ...
- B、小花梨的三角形(解题报告)
通过set进行标记(思想很简单,实现起来有点容易错)set(红黑树:效率高) 思路: 对行列和长度进行枚举: 对三个顶点进行排序 储存顶点后计数输出 #include<iostream> ...
- 2020ICPC·小米 网络选拔赛第一场 J.Matrix Subtraction (贪心,二维差分)
题意:给一个\(nXm\)的矩阵,可以选取\(aXb\)的子矩阵,使子矩阵中的所有元素减一,问最后是否能使矩阵中所有元素变为\(0\). 题解:首先贪心,我们看最左上角的元素,如果\(g[1][1]\ ...