How to achieve "Reference Variable" functionality

How to achieve "Reference Variable" functionality

I know that JS can't do reference variables like PHP (my native language), but theres gotta be some way to accomplish something similar to it, without using a global variable.

In my code, I have a function that initiates a DataTables instance (And this has nothing to do with DataTables, btw), and when DT is initiated, it launches a function that will monitor the data source of the table, and when anythings changed, it will reload the DT instance. This function that monitors the data source can be used many times.

What I'm trying to do is find a way to pause the loop that watches the data source in the second function, from the initial function. My thought right now is that maybe theres a way to pass a closure as the parameter to second function, thats defined in the first function, which will accept a local variable (local to the 2nd function) that it will toggle, which controls the loop.. Not sure thats clear enough, hope so. Kinda hard to explain


If anyone has any ideas, that would be great! thanks