Aaron You could say the same thing about a lot of the mootool array methods though couldnt you? array.empty() can just be array = [] array.each() can be done in a simple "for" loop array.getLast() can just be array[array.length-1] could go on but wont as i am sure you get the point. the framework is meant to make things easier, give you an easier simpler way to do things......wouldnt you agree? _____
From: Aaron Newton [mailto:[email protected]] Sent: Friday, 7 August 2009 1:28 AM To: [email protected] Subject: [Moo] Re: each error on IE We aren't going to add a method to array for removing items at an index. There is already a native method for this and it works just fine. 2009/8/6 Fábio M. Costa <[email protected]> This addition can be discussed. I think that splice is kind of complicated for ppl who never saw it before, ive never seen it before javascript. Dont know, you have to convince the awesome guys upstairs. -- Fábio Miranda Costa Solucione Sistemas Front-End Engineer http://meiocodigo.com On Thu, Aug 6, 2009 at 11:59 AM, Steve Onnis <[email protected]> wrote: In addition you could make it easier to use like this Array.implement({ deleteAt : function (index) { if (index > this.length-1) return; this.splice(index,1); } }); And then just call.... test_array.deleteAt(0); To be honest I am very surprised something like this isnt already in the framework Another option also is to leave what you have and do this... delete test_array[0]; test_array.clean(); I wouldn't but its an option Steve -----Original Message----- From: Steve Onnis [mailto:[email protected]] Sent: Friday, 7 August 2009 12:41 AM To: [email protected] Subject: [Moo] Re: each error on IE In the instance you have provided below yes it will cause an error as by the time you loop over "test_array" the first index is no longer there and is undefined. Even though you are deleting it the length of the array is still 2 so the first time it loops, "item" will be undefined and because it is undefined or whatever, the method "each()" is not available for a null value. To do it properly you should use splice() (https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objec <https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objec %0Ats/Array/splice> ts/Array/splice) You should really tidy up your array creation also // Create the arrays array0 = ['00','01']; array1 = ['10','11']; // COPY the arrays into new memory space to make sure // dont have a conflict when you remove the array later test_array = [$A(array0), $A(array1)] ; // Remove the first item in the array test_array.splice(0,1) // Test output test_array.each(function(items, row){ items.each(function(i, r){ document.write(r + " : " + i + "<br />" ); }); }); Steve -----Original Message----- From: Shrike [mailto:[email protected]] Sent: Thursday, 6 August 2009 8:39 PM To: MooTools Users Subject: [Moo] each error on IE Hello, can you help me to solve the IE error on this script? http://mooshell.net/gYxKu/ no errors with firefox or chrome var array0 = new Array(); array0[0] = '00'; array0[1] = '01'; var array1 = new Array(); array1[0] = '10'; array1[1] = '11'; var test_array = new Array(); test_array[0] = array0; test_array[1] = array1; delete test_array[0]; test_array.each(function(items, row){ items.each(function(i, r){ // IE error alert(i); }); });
