[javascript] Why is my JavaScript function sometimes "not defined"?