ES6字符串插值和jQuery的冲突

Conflict in ES6 String Interpolation and jQuery $

本文关键字:冲突 jQuery 字符串 插值 ES6      更新时间:2023-09-26

愚蠢的问题:别麻烦了

我是ES6的新手,在这里跟随这个指南开始。我看了下面的代码,一直在思考。

function printCoord(x, y) {
    console.log(`(${x}, ${y})`);
}

所以我们使用${VARIABLE}来获取它的值作为字符串。现在,如果我使用jQuery作为$,它会与上面的代码冲突吗?或者jQuery会忽略 `` ?

我们能不能做一些像…

console.log(`(${ $('.selector').text() })`);

它会要求我使用jQuery作为jQuery无处不在吗?

我做了一个jsfiddle。(添加jQuery, babel作为语言)

http://jsfiddle.net/kamikazefish/hd1Le21z/

<div class="selector">This is the text in the selector</div>
console.log(`(${ $('.selector').text() })`);
alert(`(${ $('.selector').text() })`);

似乎行得通