I know you can concatenate a string like this in Javascript:
str1 + str2;
Or like this:
[str1, str2].join('');
Why is there a function to do this, too?
str1.concat(str2)
Is it any faster? Just seems like more typing to me. My guess is that this was used before str1 + str2 was optimized. Would that be correct?
The
String.prototype.concatmethod is very generic (ECMA Standard 5.1 Edition / June 2011, pp.143-144):Because it’s so generic it can be used on almost every object that has a
ToString()method. See also the following note:So you can use
String.prototype.concat.call(myObject,....);. Note that there’s also aArray.prototype.concatmethod, which is also very generic (p. 125).