Creating objects within jQuery each() issue


I have a tab compopenet object that works by passing a dom element to a constructor… which then finds all the relative elements to that element using .find() and adds the necessary behaviour.

Now, since I have multiple tab components on the same page, I’m using each() to iterate through the dom elements and pass each into the tab component constructor function.

Looks something like this:

function TabComponent(el)


new TabComponent($(this));

This works fine for my purposes, but after running my code through JSLint and researching here (, I’ve been made aware that I’m pretty much throwing these objects away, since I’m not assigning them to a variable.

My question really is; is this particularly bad practice under the circumstances? If I assigned the object to a variable within .each(), I’d surely be overwriting that varibale with each iteration and essentially doing the same thing? I’m wondering how a more experienced coder would handle this?

Any help greatly appreciated.

Without knowing what TabComponent actually does, it’s hard to tell. To me it looks like it would be more appropriate to run a function inside the loop instead of creating an object - which will be discarded at the end of each iteration.