Proof (gluing lemma)

Restriction of a continuous function is still continuous.

We will use the characterisation that a function is continuous iff the preimage of any closed set is closed. Suppose $f|_A$ and $f|_B$ are continuous. For any closed set $C\subseteq Y$, we have $$ \begin{align*} f\inv(C) = (f\inv(C) \cap A) \cup (f\inv(C) \cap B) = f|_A\inv(C) \cup f|_B\inv(C). \end{align*} $$ Since $f|_A$ is continuous, $f|_A\inv(C)$ is closed in $A$, and because $A$ is closed, $f|_A\inv(C)$ is closed in $X$. Similarly $f|_B\inv(C)$ is closed in $X$ as well. Thus $f\inv(C)$ is a union of closed sets, thus closed.