Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
Thread: Creating objects within .each()
10-07-2010, 09:44 AM #1
- Join Date
- Aug 2007
- Thanked 0 Times in 0 Posts
Creating objects within .each()
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 jQuery each() to iterate through the dom elements and pass each into the tab component constructor function.
Looks something like this:
This works fine for my purposes, but after running my code through JSLint and researching here (http://stackoverflow.com/questions/2381253), 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.