-
17 Nov 2012 5:37 PM #1
Array.prototype.remove and Ext.apply - wtf ??? (bug with config of type of Array)
Array.prototype.remove and Ext.apply - wtf ??? (bug with config of type of Array)
Due to some reasons I use this code:
Ext.apply , defined in ext-base.js looks like:Code:var config = ['a', 'b']; Ext.apply(o, config);
Ok, as we see, it MUST work with array (typeof array is 'object'), but wait, Ext has defined such stupid prototype methods:Code:Ext.apply = function(o, c, defaults){ // no "this" reference for friendly out of scope calls if(defaults){ Ext.apply(o, defaults); } if(o && c && typeof c == 'object'){ for(var p in c){ o[p] = c[p]; } } return o; };
Code:Ext.applyIf(Array.prototype, { /** * Checks whether or not the specified object exists in the array. * @param {Object} o The object to check for * @param {Number} from (Optional) The index at which to begin the search * @return {Number} The index of o in the array (or -1 if it is not found) */ indexOf : function(o, from){ var len = this.length; from = from || 0; from += (from < 0) ? len : 0; for (; from < len; ++from){ if(this[from] === o){ return from; } } return -1; }, /** * Removes the specified object from the array. If the object is not found nothing happens. * @param {Object} o The object to remove * @return {Array} this array */ remove : function(o){ var index = this.indexOf(o); if(index != -1){ this.splice(index, 1); } return this; } });
Nice, remove() is enumerable! This is great, because of this brokes all for (var p in o) iterations !
Ext developers are happy, because of they can call [0,1].remove(0) instead of [0,1].splice(0,1).
But I am sad because of my server-side provides component states as arrays, not objects.
Is ExtJS 3 supported? Where is bug-tracker ? Can someone offer workaround, please (I am new to javascript and especially ExtJS)?
-
19 Nov 2012 10:45 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 34,117
- Vote Rating
- 454
Ext JS 3 is supported if you were a support subscriber, any updates are only available to support subscribers since Ext JS 4 is the current version.
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
19 Nov 2012 11:07 AM #3
No, I am not subscriber. I am developer of free extras for free CMS (MODx Revolution). So, public version will stay buggy? Fine...
-
19 Nov 2012 11:13 AM #4
hasOwnProperty check brokes Ext.grid.RowExpander.
Object.defineProperty doesnt work in IE6-8.
Very bad...
Used such workaround:
This works at least in modern browsers.Code:Object.defineProperty(Array.prototype, "remove", { value : function(o){ var index = this.indexOf(o); if(index != -1){ this.splice(index, 1); } return this; }, enumerable : false });
Thank you for reporting this bug. We will make it our priority to review this report.


Reply With Quote