Dollar sign followed by a square bracket in the pattern line

I was messing around with some ES6 code and came across this

let vendors = ['ms', 'moz', 'webkit', 'o'];
let root = window || global;
let performance = window.performance || {};
if (!performance.now) {
  vendors.some(function(vendor) {
    performance.now = performance[`$[vendor}Now`];
    ...

I can guess what the following code does, but what is the library / syntax? This is not what I have ever seen before, and it is not pure ES6, right?

`$[vendor}Now`
+4
source share
1 answer

This seems to be a syntax error. The right thing should be:

`${vendor}Now`

This is the dollar expression that is mentioned here: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/template_strings

(`) ( ) . . ($ {}).

.

, :

var expression = 'test';

console.log(`string text ${expression} string text`); //Correct syntax

: " "

var expression = 'test';

console.log(`string text $[expression} string text`); //Wrong syntax

: "string text $[} "

+9

Source: https://habr.com/ru/post/1607148/


All Articles