Then how is the momentum operator defined?Are you referring to the place where they say that the partial derive of psi gives p psi, that it suggests the partial derivative is the momentum operator?
They did not "cancel out" the function. The operation there was not "it therefor follows" but rather "it suggests." Getting from the one equation to the other has more support than they have given there. But it's quite a bit more complicated than the typical wiki article.