Observed this behavior today: I created a function f() {} (literally did nothing), then called locusZoomPlot.onUpdate(f). That worked fine; however, the second call to onUpdate() (without argument, so therefore intending to run all of the stored functions) would yield a Uncaught TypeError: this.onUpdateFunctions[func] is not a function.
I replaced the onUpdate function with the following:
Using this, I could see that f got added correctly. However, when onUpdate() was called the first time, this.onUpdateFunctions became [function function, undefined: undefined]. Further inspection showed that when onUpdateFunctions was called the first time without argument, it would iterate over the following values: 0, shuffle, swap, heapSort. 0 makes sense, as an array indice. The last 3 are surprising--this.onUpdateFunctions["shuffle"]() and this.onUpdateFunctions["heapSort]()" don't seem to do anything, but this.onUpdateFunctions["swap"]() seems to be adding the undefined to onUpdateFunctions. Not entirely sure where these are coming from--I assume it has something to do with the prototype methods for arrays in javascript, but some quick research didn't seem to show anything.
The fix seems to be swapping out the iteration like so:
Observed this behavior today: I created a function
f() {}
(literally did nothing), then calledlocusZoomPlot.onUpdate(f)
. That worked fine; however, the second call toonUpdate()
(without argument, so therefore intending to run all of the stored functions) would yield aUncaught TypeError: this.onUpdateFunctions[func] is not a function
.I replaced the
onUpdate
function with the following:Using this, I could see that
f
got added correctly. However, whenonUpdate()
was called the first time,this.onUpdateFunctions
became[function function, undefined: undefined]
. Further inspection showed that whenonUpdateFunctions
was called the first time without argument, it would iterate over the following values:0
,shuffle
,swap
,heapSort
.0
makes sense, as an array indice. The last 3 are surprising--this.onUpdateFunctions["shuffle"]()
andthis.onUpdateFunctions["heapSort]()"
don't seem to do anything, butthis.onUpdateFunctions["swap"]()
seems to be adding theundefined
toonUpdateFunctions
. Not entirely sure where these are coming from--I assume it has something to do with the prototype methods for arrays in javascript, but some quick research didn't seem to show anything.The fix seems to be swapping out the iteration like so:
I'll make up a PR here in a minute.
tl;dr: the way JS handles iteration over an array doesn't always seem to work correctly, which results in
undefined
getting added toonUpdateFunctions