doc undefined in function