nested functions & callbacks
Attempting to figure out more specifically what happens when functions are nested & mixed with callbaks.
by Matt Rummler
JavaScript
/*
Having a real world problem with nested callbacks.
Without implementing a promise architecture (which might not solve the problem anyway) I am going to test out what EXACTLY happens when I nest certain constructs in callbacks that are callbacks to callbacks
(which is about the level I'm having a problem with)
NOTE: I originally saw this problem when I passed a callback that is assigned to the property of an object... which, to me, makes it more insane and makes it likely the problem is in the way js decided to execute the code...
VERSION: 1 && 1.1
This version shows the weaknesses of attempting to pass multiple callbacks through a single anonymous function.
Additionally adding additional anonymous functions may work but makes a seriously messy blotch of code.
NOTE: the only callbacks that are needed are in the first & third functions... this is too arbitrary to be useful though
NOTE2: for V1.1 I added a fifth function to see what would happen if I let 4 have a callback that it could call...
The affects on what ran are negative 2 & 3 no longer run... this probably means I have to remove the callback in 3 I will try for version 1.2
NOTE3: (version 1.2 & 1.3):
1.2 showed no changes 3 & 2 still do not run... also changed 2 so it has a callback again, no change
1.3 for this version I will add all callbacks back (though not add one to 5) & then call each in it's own anonymous function... which is going to be really messy
FINAL 1.3 NOTE: SUCCESS (kind of) putting each part in it's own anonymous function worked... the functions are firing in the correct, sequential order.
Unfortunately this is really messy code and I'd like to find a better way to do it.
VERSION: 2
This version (starting @ the 4th version of this jsFiddle) attempts to utilize an object that contains references to each function.
I do not know if this successfully constitutes a closure as V1.3 does (with it's anonymous functions wrapping each function reference)
V2 RESULTS: DOESN'T WORK
This object...