Clone javascript function