Just recently I found this to be working:
const str = "foo bar";
const arr = str.split` `; // <- no parens
console.log(arr);
// -> ["foo", "bar"]
It seems like the split
prototype is a tagged template literal. I also saw this working with other array functions like indexOf
.
Is there a specific reason for implementing this behavior? Can I do something with it that I could not do before or can I solve some tasks in a simpler way?
It seems that there has been some effort put into the implementation, and every use-case that I can think of would just overcomplicate things. It seems to me like a waste of time to make it possible. Or did it come at zero cost? If so: How?