Szychowski: And i told you to put that var INSIDE the callback.
Szychowski: Bazan one thing at a time :
Szychowski: They need to get the scoping problem first.
Szychowski: Berpcor https://jsfiddle.net/Szychowski/qvh4oabj/
Szychowski: Though Bazan has a very salient point that we’ll talk about in a second.
Baldrige: Moving the function outside the loop forces a scope re-think. That was my whole angle 😛
Szychowski: Heh, he needs to undestand the scope to begin with.
Carothers: Ok, I move it outside for loop, but how I’ll write it there? Manually for each of 7 images?
Szychowski: This is why i wasn’t suggesting that quite yet heh
Stroup: Haha, okay, I’ll back off.
Szychowski: You’d write a function that you’d call within the for loop.
Sprinkle: Berpcor2: Szychowski and I were attacking it from completely different angles. Sorry I made it confusing for you.
Szychowski: Heh, going to get to the same end result though.
Maltese: Sorry? Now sorries. You are tried and trying to help
Szychowski: I’m going to save you some guesswork on this one: https://jsfiddle.net/Szychowski/ny3vku7w/1/
Szychowski: Though that return isn’t in a very good place.
Szychowski: And that’s where this gets REALLY confusing :
Szychowski: Because now var r = mgallery.getAllWardrobeData; doesn’t work.
Szychowski: Sure, but you’re confusing vars again.
Szychowski: For loops don’t have scope.
Szychowski: And you don’t need curIndex
Szychowski: Look at the fiddle i sent.
Szychowski: But this approach won’t work without you reworking lots of other code because you need to start using deferreds./
Szychowski: Because you can’t use return result; that way.
Mandap: Why I can’t return that way?
Szychowski: Because .load is asynchronous.
Szychowski: And the callback isn’t returning to the function you think it is.
Arboleda: So it returns to. nowhere?
Szychowski: It returns to jquery.
Szychowski: You can’t capture it.
Spadaccini: Well. yes, async functions were created for different purposes.
Philp: It is not target use.
Szychowski: That’s nopt realy way.
Szychowski: It’s because the browser would have to stop everything it’s doing and wait for the call to finish before it’d know what to do next.
Szychowski: This is a good basic tutorial for jquery with some general js stuff thrown in.
Ulisch: What if my array of data won’t be formed by the time I need it as load is async, what if there would be some problem about getting access to files? Is that possible?
Szychowski: Right, so the real way you fix this is learn promises.
Lanford: So, the main idea is I won’t loose control upon any action?
Szychowski: The main idea is you can’t execute some things until others have finished.
Szychowski: So you use promises to control that.
Werk: I think that I shouldn’t use it in my case. That’s why. I do all that stuff when I click on some image. Click initialize jquery plugin image gallery. So, user will have to wait until all operations will be done.
Szychowski: Otherwise your code will never work.
Noffsinger: What are the cases for using this functionality?