Generic functions for javascript