Is there a map () function in ExtJS?

ExtJS has an Ext.each () function, but is there any mapping () also somewhere?

I tried very hard, but did not find anything that could fill this role. It seems to be something simple and trivial that a JS library as large as Ext should have.

Or, if Ext doesn't really include it, what would be the best way to add it to Ext. Of course, I can just write:

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

But is this really the right way to do this?

+4
source share
5 answers

It looks like my colleges here are using ext-basex , which extends Array.prototype with map () and other methods.

Therefore, I can simply write:

 [1, 2, 3].map( function(){ ... } ); 

The problem is resolved.

+2
source
+3
source

Since map more useful than anything, I don’t understand why there is any special way to connect it to the Ext namespace; how you suggest will work quite well, although you can do it like this:

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

Everything seems to be fine ... but then I do not use ExtJS, so I do not know. I made a gander in their docs, and it doesn't seem like there is anything special in this case.

+2
source

How about using one of the hybrid libraries like Ext + Prototype or Ext + JQuery. I used Extjs + Prototypejs for a while, and it helped me to work a lot in Extjs code, having even more familiar prototypes for driving.

http://extjs.com/products/extjs/build/ will create a custom tar / zip file for all the files needed to run extjs, and (prototypejs | jquery | yahooUI).

+1
source

ExtJS does not replace JavaScript itself. Array functions are not the focus of ExtJS core. However, there is a special type of Ext.Array object. You can expand it by yourself.

EDIT: not Ext.Array, but just an extended Array object.

0
source

All Articles