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,意思 ...
随机推荐
- 不占用额外内存空间能否做到 将图像旋转90度 N × N矩阵表示的图像,其中每个像素的大小为4字节
给定一幅由N × N矩阵表示的图像,其中每个像素的大小为4字节,编写一种方法,将图像旋转90度. 不占用额外内存空间能否做到? 示例 1: 给定 matrix = [ [1,2,3], [4,5,6] ...
- (Oracle)误删oracle表结构恢复
在操作数据库时,我们常常会不小心把表结构删除了.有时候建表很麻烦大到100多个字段,而又找不到当初的建表语句.其实这时候不用担心,oracle和咱们widows一样,他也有个回收站,只要你没有清除回收 ...
- setTimeout、Promise、Async/Await 的区别
事件循环中分为宏任务队列和微任务队列其中setTimeout的回调函数放到宏任务队列里,等到执行栈清空以后执行promise.then里的回调函数会放到相应宏任务的微任务队列里,等宏任务里面的同步代码 ...
- Python学习【第5篇】:数据类型和变量总结
字符串,数字,列表,元组,字典 可变不可变 1.可变:列表 如: p.p1 { margin: 0; font: 11px Menlo; color: rgba(0, 0, 0, 1); backgr ...
- C# 实现一个基于值相等性比较的字典
C# 实现一个基于值相等性比较的字典 Intro 今天在项目里遇到一个需求,大概是这样的我要比较两个 JSON 字符串是不是相等,JSON 字符串其实是一个 Dictionary<string, ...
- JavaScript——事件
事件:是由访问Web页面的用户引起一系列操作. 事件的作用:用于浏览器和用户的交互 以下代码为相关试验代码: HTML事件: <script type="text/javascript ...
- 织梦dedecms自由列表的"不使用目录默认主页"错误修正
站长用织梦做站时常常发现织梦自由列表有个致命的问题: 即修改"不使用目录默认主页"就永远不会自己勾选啦 打开这个文件 makehtml_freelist_action.php 搜索 ...
- 【实战】通过Python实现疫情地图可视化
目录 一. json模块 二.通过Python实现疫情地图可视化 2.将json格式的数据保存到Excel 3.应用pyecharts进行数据可视化 一. json模块 JSON(JavaScript ...
- Yacc使用优先级
Yacc使用优先级 本示例是龙书4.9.2的示例,见图4-59. 和前一章一样,新建xUnit项目,用F#语言.起个名C4F59安装NuGet包: Install-Package FSharpComp ...
- .Net技术栈下的异步,你还在用同步方式进行开发吗?
关于异步,其实是个老生常谈的话题,也是各大公司面试常问的问题之一.本文就几个点来介绍异步解决的问题 注:对多线程的运行的基本机制要了解 1.介绍 有人可能会有疑问,为什么并行,非得用异步.多线程也已可 ...