DEFINE A FUNCTION WITHIN ANOTHER FUNCTION IN JAVASCRIPT