Recursion on a class instead of a set According to Wikipedia, the recursion theorem states the following:

Let $X$ be a set, and $f:X\to X$ a function. For any $x\in X$, there exists a unique function $g:\omega\to X$ such that $g(0)=x$ and
  $$g(S(n))=f(g(n))$$
  for all $n\in\omega$.

My question is: is the recursion theorem still valid if $X$ is a class instead of a set (and $f$ is a functional relation)?
 A: Indeed, if you look at the proof of the recursion theorem, you should find that at no point is the fact that $X$ is a set ever used.
There's actually a more general version than that, though, called Transfinite Recursion. See Wikipedia again for more info.
A: If you're not comfortable with Cameron's answer which points out that we didn't really use the fact that $X$ is a set, in order to extend this to proper classes, let me point out a different angle.
Assuming $\sf ZFC$ every class can be written as an increasing union of sets (simply consider $X_\alpha=X\cap V_\alpha$, then $X$ is the union of $\{X_\alpha\mid\alpha\in\rm Ord\}$). If we can find some $\alpha$ such that $f[X_\alpha]\subseteq X_\alpha$, and $x\in X_\alpha$, then we can use the usual theorem to construct $g$. Then we can show that this doesn't depend on the choice of $\alpha$.
For the first step we can either do this by hand, by considering $X_{\alpha_0}$ to be any $\alpha_0$ such that $x\in X_{\alpha_0}$, then $X_{\alpha_{n+1}}=X_{\alpha_n}\cup f[X_{\alpha_n}]$, and defining $X_\alpha=\bigcup_{n\in\omega} X_{\alpha_n}$. But you might point out, rightfully, that this makes an appeal to the recursion theorem applied to a proper class. 
Instead we can also prove this using the reflection theorem. Since $X$ and $f$ are definable (being classes), $\langle V,\in\rangle$ satisfies the statement that the function defined by $f$ is from the class defined as $X$ to itself. This gets reflected at some $V_\alpha$, namely there is some $\alpha$ such that $\langle V_\alpha,\in\rangle$ satisfies that $X\cap V_\alpha$ is closed under $f\restriction X\cap V_\alpha$. Now using the recursion theorem we can find $g$ as wanted, and we can prove that if $\alpha,\beta$ are two sets obtained this way, then $g$ defined in each of them is equal.
(But generally, Cameron is right, and there's nowhere we use the fact that $X$ is a set. The transfinite recursion theorem makes it clearer.)
