how to stop a function in javascript