PDA

View Full Version : Ext.string.format v/s String concatenate operation



AJAIN32
24 Apr 2015, 9:04 AM
Hi,

I am using some concatenation operations in my extjs code -

sample 1 - var str = string1 + '-' string2 + '-' + string3 + ...
sample 2 - var str = Ext.String.format('{0} - {1} - {2}', string1, string2, string3)..

I think Ext.string.format should be more faster, but when i checked on this link -
http://jsperf.com/ext-string-format-vs-concat
it is showing it slower.

can anyone please tell me which one is faster ?

Thanks,
Ankit

tristan.lee
24 Apr 2015, 12:13 PM
Hi,

Using the native form on String concatenation is going to be faster as Ext.String.format() (http://docs.sencha.com/extjs/4.2.1/source/String2.html#Ext-String-method-format) uses a regular expression for token replacement.

Thanks,
Tristan