Fix undefined function js error