I am going through Axler's "Measure, Integration and Real Analysis" and have a question about his proof that continuous functions are Borel measurable. There has been a question about this (Every continuous function is Borel measurable.) but it doesn't really answer mine:
The statement is that if $X \subset \mathbb R$ a Borel subset of $\mathbb R$ then every continuous function $f: X \to \mathbb R$ is Borel measurable.
Axler defines a Borel measurable function as a function $f:X \to \mathbb R$ for which $f^{-1} (B) \subset X$ is a Borel set for every Borel set $B \subset \mathbb R$.
To prove the claim an $a \in \mathbb R$ is fixed. Now if $x \in X$ and $f(x) > a$ then the continuity of $f$ implies $\exists \delta_x > 0$ such that $\forall y \in (x - \delta_x, x+ \delta_x) \cap X$ it will be the case that $f(y) > a$. It then follows that $$ f^{-1} ((a,\infty)) = \left( \bigcup_{x\in f^{-1} ((a,\infty))} (x - \delta_x, x+ \delta_x) \right) \cap X $$ So we can conlude that $f^{-1} ((a,\infty))$ is a Borel subset of $\mathbb R$ contained in $X$. Since $a$ is arbitrary then $f$ is Borel measurable.
My question: I understand the proof in principle, but shouldn't the domain of $f$ be an open set containing $X$? Otherwise I don't see why the intersection with $X$ needs to be taken. And indeed if $X$ is eg a closed interval, to make the proof work I think $f$ needs to be defined on some open subset containing $X$. The way I read the claim and proof is that the domain of $f$ is strictly $X$.
EDIT: I think I understand where I went wrong. It's fine that the domain of $f$ is strictly $X$, as this is already taken care of by the statement by the "$\forall y \in (x - \delta_x, x+ \delta_x) \cap X$". And everything else in the proof then follows.