The continuity of function's restrictions implies the continuity of function. Let be $X \subset F_1 \cup F_2$, where $F_1$ and $F_2$ are closed. If the function $f\colon X \longrightarrow \mathbb{R}$ is such that $f|_{X \cap F_1}$ and $f|_{X \cap F_2}$ are continuous, so prove that $f$ is continuous. 
My attempt:
Suppose that $f$ is discontinuously, so exists $x \in X$ such that $f$ is discontinuously in $x$, but $X \subset F_1 \cup F_2$, therefore, if $x \in X \cap F_1$, so $f|_{X \cap F_1}$ is discontinuously in $x$ which is absurd because contradicts the hypothesis. Analogously, if $x \in X \cap F_2$, we have a contradiction.
That's my answer, but I don't sure if it's correct, because I didn't use the hypothesis that $F_1$ and $F_2$ are closeds. I would like to know if my attempt is correct. Thanks in advance!
EDIT: $X \subset \mathbb{R}$
 A: HINT: Something similar to your approach is workable, but you’ve omitted most of the crucial details. In particular, you’ve not justified the assertion that $f\upharpoonright X\cap F_1$ is discontinuous at $x$. 
Suppose that $f$ is not continuous at $x$; then there are an $\epsilon>0$ and a sequence $\langle x_n:n\in\Bbb N\rangle$ in $X$ converging to $x$ such that $|f(x_n)-f(x)|\ge\epsilon$ for each $n\in\Bbb N$. (Why?) Let 
$$N_1=\{n\in\Bbb N:x_n\in F_1\}$$
and
$$N_2=\{n\in\Bbb N:x_n\in F_2\}\;;$$
clearly $N_1\cup N_2=\Bbb N$, so at least one of the sets $N_1$ and $N_2$ must be infinite. Without loss of generality suppose that $N_1$ is infinite. 


*

*Explain why $x\in X\cap F_1$.  

*Use $N_1$ to show that $f\upharpoonright X\cap F_1$ cannot be continuous at $x$.

A: Complementing @BrianMScott's answer, one could also avoid the proof by contrapositive/contradiction/whatever by claiming that any $x\in X$ has a sufficiently small neighborhood (if you like, the intersection of $X$ with a $\delta$-ball around it) lying entirely inside either $X\cap F_1$ or $X\cap F_2$. Then continuity of the respective restriction (or both) give continuity at $x$. This is where the closedness is used, since the complements of $X\cap F_1$ and of $X\cap F_2$ are open.
A: The proof falls when you pick a point on an edge. If the intervals don't overlap then the proof works fine. But when you are on the edge of the interval then you know that there is only one sided continuity. This is (I guess) where the closed part should be. For example: $f:X \rightarrow \mathbb{R}$, such that $X = [-1,0] \cup (0,1]$, and $f(x) = \sin(1/x)$ for $x \in (0,1]$ and 0 otherwise. f in continues at each interval but in x=0 the right limit does not exist. Then in your proof, the fact that the intervals are closed assures you that such situation cannot exist. Also I have assumed that $F_1$ and $F_2$ are intervals, I'm not sure if this is correct for any closed set (for example the Cantor set).
A: We can be a bit more general. Let $X = A\cup B$ be such that $A-B$ and $B-A$ are separated. For any subset $E$ of $X$, its $X$-closure is the union of the $A$-closure of $E\cap A$ and $B$-closure of $E\cap B$. That is,
$$
\bar{E} = \left(\overline{E\cap A} \cap A\right) \cup \left(\overline{E\cap B} \cap B\right).
$$
To prove it, note that (since closure of union of two sets is the union of their closures)
$$
\bar{E} = \overline{E\cap A} \cup \overline{E\cap(B-A)}.
$$
Consequently
$$
\bar{E}\cap A = \left(\overline{E\cap A} \cap A\right)\cup \left(\overline{E\cap(B-A)}\cap A\right).
$$
Since $X = A\cup B$ and $\overline{B-A} \cap A-B = \varnothing$, $\overline{B-A} \subset B$. Hence $\overline{E\cap(B-A)} \subset B$. Note that we also have  $\overline{E\cap(B-A)}\subset \overline{E\cap B}$. Therefore, $\overline{E\cap(B-A)} \subset \overline{E\cap B} \cap B$. To conclude,
$$
\bar{E}\cap A \subset \left(\overline{E\cap A} \cap A\right)\cup \left(\overline{E\cap B} \cap B\right).
$$
The same holds for $\bar{E}\cap B$. Hence
$$
\bar{E} \subset \left(\overline{E\cap A} \cap A\right)\cup \left(\overline{E\cap B} \cap B\right).
$$
The other direction is rather obvious.
With the same $X$, suppose that $f:X\to Y$ is such that both $f|_A$ and $f|_B$ are continuous. Then $f$ is continuous on $X$. To prove it, let $F$ be a closed set in $Y$, and put $E = f^{-1}(F)$. Then ${f|_A}^{-1}(F) = E\cap A$, and ${f|_B}^{-1}(F) = E\cap B$. Since $f$ is continuous on $A$ and $B$, $E\cap A$ and $E\cap B$ are closed in $A$ and $B$ respectively. By our previous formula,
$$
\bar{E} = (E\cap A) \cup (E\cap B) = E,
$$
so $E$ is closed. Hence $f$ is continuous on $X$.
To apply the result to your case, note that when $A$ and $B$ are both closed, $A-B$ and $B-A$ are separated. The reason is that both are open in the subspace $A-B \cup B-A$.
