Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a map() function in ExtJS?

ExtJS has Ext.each() function, but is there a map() also hidden somewhere?

I have tried hard, but haven't found anything that could fill this role. It seems to be something simple and trivial, that a JS library so large as Ext clearly must have.

Or when Ext really doesn't include it, what would be the best way to add it to Ext. Sure, I could just write:

Ext.map = function(arr, f) { ... };

But is this really the correct way to do this?

like image 362
Rene Saarsoo Avatar asked Mar 01 '23 05:03

Rene Saarsoo


2 Answers

As of at least Ext4, Ext.Array.map is included.

http://docs.sencha.com/extjs/5.0.1/#!/api/Ext.Array-method-map

like image 90
David Kanarek Avatar answered Mar 11 '23 00:03

David Kanarek


Since map is more of a utility than anything, I don't see why there would be any special way of plugging it into the Ext namespace; the way you propose would work well enough, though you might want to do it thusly:

if(Ext && typeof(Ext.map) == "undefined") { // only if Ext exists & map isn't already defined
   Ext.map = function(arr, f) { ... };
}

Seems like that would be fine...but then, I don't use ExtJS, so I don't know. I did take a gander at their docs and it doesn't seem like there is anything special to do in this case.

like image 39
Jason Bunting Avatar answered Mar 11 '23 01:03

Jason Bunting