Is there a function to simply reset all JS functions?

Is there a function to simply reset all JS functions?
0.0 0

#1

Hi there,

I am just wondering if there is a function that would reset all the functions without refreshing the page?

So literally, on the click of a reset button, everything is reloaded and back to initial state.

However I don’t want to reload the page.

This is for my tic tac toe board zipline btw.

Thanks!

for reference, here’s my codepen so far => http://codepen.io/JackEdwardLyons/pen/WGvrEd?editors=1011


#2

Could you put all the functionality into one larger function that is called on page load (the first time) and can be subsequently fired every time a particular button is pressed?


#3

You could try codepen’s run button. Just go to settings, then click on behavior and uncheck “Auto-Updating Preview.” This will add a run button to the page beside save, which effectively just refreshes the preview, and is much faster than refreshing the entire page.


#4

State is something you define as the programmer, so an initializing function is something you’d have to implement. Ideally, you’d already have a function that gets the game into its prime state that you could call for this.


#5

yeah i created an init function – but i wasn’t sure how to recall it on click.

I tried simply referencing it within the click handler like so: init() but that didn’t change the state.


#6

When you say “change the state”, what do you expect to happen?


#7

all the tiles to be wiped and the counter reset basically


#8

There’s nothing in init() that sets the counter, and the code that sets up the tiles just adds divs to the document and adds an event listener. Each time you invoke the function, you’re just adding to the DOM. In order to reset, you’ll need to clear out whatever was there before.