Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ext.String.format enhancement in EXTJS

Tags:

extjs4

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?

like image 375
Shakti Singh Avatar asked Nov 01 '22 04:11

Shakti Singh


1 Answers

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];
        });
    }
like image 101
CD.. Avatar answered Nov 17 '22 05:11

CD..