Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How do I call the getStatus() function inside the anonymous closure. If you look

ID: 3716668 • Letter: H

Question

How do I call the getStatus() function inside the anonymous closure. If you look at the bottom, on click I want to execute the getStatus() function again. Unfortunately, its out of scope and I have no idea how to get to it. When I include the onclick function under the Create Table comment, it runs into a recursive problem. First call, call getStatus once. Second call, it calls getStatus twice, and so on and forth. So, I need another solution to call the getStatus function without running into recursive problems.

/Main function $(document).ready(function) Anonymous Closure to protect functions and values var setupStatusPage (function) /7 Get Master.JSON varget "master.json"); 17 Done _.then (function(data) /Determine if site is allstatus or index va r ur? = $(location).att r('href').split ('/').pop(); // Status function getStatus() /Get STATUS var status data.map(get) /All status Done, include status to data array some(status).then (function(results) Animation loader -remove class when done $ ( #load ing1' ) . removeClass ( ) ; $ ( #load ing2' ) . removeClass ( ) ; 11 Create Table if (uri 'allstatus) createStatusTable(data); H: getStatus); )i HO; // Reload Status function $('#reload').on("click.., function () { Animation Loader -add class //S('#loading1' ) .addClass(' overlay2' ) ; //s(' #loading2' ) .addClass(' loader' ) ;- getStatus) H) H)

Explanation / Answer

Well you can move the definition of the function getStatus(var data) with global scope (i.e., at the beginning of the script).

Please note that it needs to have one arguments "data" passed to it as it needs data to find the status.

Once you created the definition of getStatus(var data), just call ths function inside setupStatusPage() and on button click.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote