javascript console.log new feature with 'raw'?
javascript console.log new feature with 'raw'?
我遇到过这个例子,完全迷路了…
const test = (hey) => console.log(hey);
console.log(test `wtf`);
首先这些都是有效的,在console.log中,它看起来是
["wtf", raw: Array[1]]
这就像函数被执行和额外的raw
?有人能解释一下吗?
这只是一个标记模板文字。它看起来很别致,但没有什么特别之处。注意,它们是ES6/ES2015的一部分,所以如果你打算支持旧的浏览器,你需要转换它们。
模板字面值是允许嵌入表达式的字符串字面值。您可以使用多行字符串和字符串插值功能。在ES2015/ES6规范的早期版本中,它们被称为"模板字符串"。
感谢@karmuran和@ decze
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals Tagged_template_literals
原始字符串
特殊的raw属性,在标记模板字面值的第一个函数参数中可用,允许您在输入原始字符串时访问它们。
function tag(strings, ...values) {
console.log(strings.raw[0]);
// "string text line 1 'n string text line 2"
}
tag`string text line 1 'n string text line 2`;
相关文章:
- Fighting with FRP
- issue with FB.Event.subscribe
- geolocation-marker.js conflict with markerclusterer.js
- Angular 2.0 with JavaScript or TypeScript?
- 为什么不推荐使用“with”?是否有更好或其他方法可以“下降”到对象的命名空间
- WebComponentsJS with IE10
- 指令的模板必须只有一个根元素:With restrict E&替换true
- timeago.js with datatable and PHP
- Ajax and Json with Rails
- errors with Javascript try catch
- how to split a string with ','
- Understanding Javascript scope with "var that = this&qu
- Architecture for CPU intensive tasks with NodeJS & Socke
- How to declare a Map containing certain properties with flow
- 设置'这'在React with Inverse Data Flow中
- Unit-testing multiple use cases with Karma & Mocha.js
- Modify Javascript with C#
- 谷歌地图API v3:Initial View is Fine,but Gray Box with No Map if
- Wordpress AJAX with raw javascript? NO Jquery
- javascript console.log new feature with 'raw'?