Search code examples
extjs4

Ext.String.format enhancement in EXTJS


I am new to ExtJS. I came across following piece of code:

Ext.String.format('<a href="mailto:{0}">{1}</a>',value+"@abc.com",value);

Now this will create a mailto link. But my query is that how Ext.String.format works and what else can I use it for?


Solution

  • Ext.String.format:

    Allows you to define a tokenized string and pass an arbitrary number of arguments to replace the tokens. Each token must be unique, and must increment in the format {0}, {1}, etc.

    You can look at the source of the function and see it uses the formatRe regex (/\{(\d+)\}/g):

    format: function(format) {
            var args = Ext.Array.toArray(arguments, 1);
            return format.replace(formatRe, function(m, i) {
                return args[i];
            });
        }