Python like function for javascript