While testing JavaScript ES6's new template strings (in Firefox, if it matters), I noticed some inconsistencies in their types.
I defined a custom function, like this:
function f(a) { console.log(typeof(a)); console.log(a); } First, I tested the function "normally", using parentheses around the template string.
f(`Hello, World!`) As expected, this yielded a type of string and Hello, World! was outputted to the console.
Then I called the function shorthand, without the parentheses, and inconsistencies occurred.
f`Hello, World!` The type became object, and Array [ "Hello, World!" ] was outputted to the console.
Why was the template string wrapped in an array when using the second method? Is this just a bug in Firefox (ES6 is a new standard, after all) or is this behavior expected for some reason?
console.log`a ${1} b ${2} c`;to understand better what's happening. By omitting the parenthesis, you've completely change the meaning of your statement: you're not simply calling the function any more, but you're using a tagged template. Yep, this syntax sucks.