On Mon, May 5, 2008 at 7:04 PM, kangax <[EMAIL PROTECTED]> wrote: > > Justin, > there's no need to "wrap" array with $A. Array.prototype is already
Thanks for the tip, I'm paranoid. IE has scarred me. I'll try to remember that. I usually initialize with this.foo = $A(), so that's what I was doing in my example. > I'm not sure why you would want to "compact" a result in first If you don't do that, then don't you end up with an undefined wherever an item was pulled out of the array? Such as in my example: [1,2,3,undefined,5] I'm getting mixed results in firebug and my ruby coding has trained me to compact my arrays. > #without is generally slow when it comes to huge arrays. Good to know. > For best performance it's obviously better to stick to native methods: > > var arr = [1,2,3,4,5]; > arr.splice(arr.indexOf(4), 1); > arr; // [1,2,3,5] I wasn't aware of a splice method. After explaining my problem a co-worker was talking about splicing and lamented that JavaScript probably did not support a splice method natively :p > Regarding your snippet, what about something like: > // it might sense to use iterator-like "proxy" for filtering > SomeClass.condition = function(value, index) { > return index % 2; > } > > var SomeClassManager = { > trim: function() { > this.objects = this.objects.reject(SomeClass.condition); > } > } > SomeClassManager.trim(); > SomeClassManager.objects.size(); // 6 Thanks, I think that is what I need. What I'm doing here is creating a new instance of my class for some special DOM elements on a page and I want a way to determine if the element is still in the page, so I have a isOrphaned() method on the class, and when that method returns true then I call that object's destroy method and then rip it out of the array. I was trying to avoid cloning the enumerable, hence the original question. -justin --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---