Are "locally continuous" functions continuous?

Let $A$ and $B$ be topological spaces and $f : A \rightarrow B$ be a function.

I call $f$ locally continuous if every $a \in A$ has an open neighborhood $U \subseteq A$ with the property that $f : U \rightarrow B$ is continuous.

Obviously, if $f$ is continuous, then it is locally continuous: if $X \subseteq B$ is open, then $f^{-1}(X) \subseteq A$ is open, and so is $f^{-1}(X) \cap U$ for any open set $U \subseteq A$.

Is every locally continuous function also continuous?


YES.

It suffices to show that if $W\subset B$ is open in $B$ then $f^{-1}[W]$ is open in $A$.

We know that, for every $x\in A$, there exists an open $U_x\subset A$, $x\in U_x$, such that $f^{-1}[W]\cap U_x$ is open in $U_x$ and hence it is open in $A$. But $\bigcup_{x\in A}U_x=A$ and hence $$ f^{-1}[W]=\bigcup_{x\in A} f^{-1}[W]\cap U_x. $$ The right hand side is an union of open sets, and hence open.


An other way, using the following well-known fact:

$f: A \to B$ is continuous iff for all $x \in A$ and every open neighbourhood $V$ of $f(x)$ we have an open neighbourhood $U$ of $x$ such that $f[U] \subseteq V$.

Now, if $V$ is open and contains $f(x)$, find $U_x$ as promised by local continuity for $x$ and note that $U=f^{-1}[V]$ is open in $U_x$ (hence open in $X$ too) and hence an open neighbourhood of $x$ as required in the above fact.