Shared Function Javascript Pattern