javascript function reordering