Use .applescript.js extension instead of .scpt
Define the next() function before calling it