Question on one theorem for uniform continuity. In my text book, one theorem states this. A real-valued function $f$ on $(a,b)$, is uniformly continuous on $(a,b)$ if and only if it can be extended to a continuous function $g$ on $[a,b].$ And the book gives two examples. The first example says that the function $f(x) = x \sin (\frac{1}{x})$ for $x \in (0,\frac{1}{\pi}]$ is uniformly continuous because it can be extended to 
$$g(x) = \begin{cases}
      x \sin(\frac{1}{x}) & 0<x\leq \frac{1}{\pi}\\
      0 & x=0.
\end{cases}$$
The second example is for the function $h(x)=\sin(\frac{1}{x})$, and it says that it can be extended to a closed interval but not uniformly continuous. And what does it mean a function can be extended to other function? Can anyone explain why is this true?
 A: In this example extending a function means that you can include the endpoints in the domain by defining values for the function at the endpoints as you did for $f$, extending the domain to include $a$ and $b$ ($0$ and $\frac{1}{\pi}$). For $g$ this works because you get continuity at $x=0$, and uniform continuity on the domain. For $h(x)$ this will not work. Consider what you would extend the function $h(x)$ to be at $x=0$. Or, what would you set $h(0)$ equal to to make it continuous at $x=0$? This is impossible. You can set $h(0)=0$, but then the function is not continuous at $0$. This relates to the topologist sine curve. As $x\rightarrow 0$, $h(x)$ oscillates infinitely rapidly so the limit is not well defined.
Regarding your question about extending a function, note we can define any function to anything we wish as long as it is well defined. For example, consider $q(x) = x$ on $[0,1]$. I can extend $q$ to also be defined on $(400,1200)$ by saying
$q(x) = \begin{cases}
x & x\in[0,1]\\
\sin(x+40\pi) & x\in (400,1200),
\end{cases}$
but you don't have continuity between the two intervals, only inside of them.
A: Let $S \subset T$ with functions $g : T  \to \mathbb{R}$ and $f : S \to \mathbb{R}$. Then $g$ is called an extension of $f$ if for every $x \in S$, $g(x) = f(x)$. Symbolically, $g|_S = f$. So, to say that there is a continuous extension $g : [a,b] \to \mathbb{R}$ of $f : (a,b) \to \mathbb{R}$ means that $g$ is continuous and for every $x \in (a,b)$, $g(x) = f(x)$.  
For an outline of how to prove the theorem (ie. why to believe it):
Assume that $f : (a,b) \to \mathbb{R}$ has a continuous extension $g:[a,b]\to \mathbb{R}$. Let $\epsilon  >0$ and, since $g$ is continuous on the compact subset $[a,b]$ it is uniformly continuous, we can find some $\delta > 0$ such that for any $x, y \in [a,b]$ with $|x-y|<\delta$ it holds that $|g(x) - g(y)|<\epsilon$. But, if $x, y \in (a,b)$ with $|x-y|<\delta$ we have $|f(x) - f(y)|=|g(x)-g(y)|<\epsilon$. So, it is true that $f$ is uniformly continuous as well.
On the other hand, if $f$ is uniformly continuous on $(a,b)$ take a sequence of points $x_n \in (a,b)$ such that $x_n \to a$. Now, using that $f$ is uniformly continuous, you can show that the sequence $\{f(x_n)\}_{n=1}^{\infty}$ is a Cauchy sequence. Indeed, let $\epsilon > 0$ and find $\delta > 0$ such that if $x, y \in (a,b)$ with $|x-y| < \delta$ then $|f(x) - f(y) | < \epsilon$. But then, since $x_n \to a$, the sequence $\{x_n\}_{n=1}^{\infty}$ is Cauchy. So there is some $N$ such that if $n, m \geq N$, then $|x_n -x_m|<\delta$. Therefore, $|f(x_n) - f(x_m)|<\epsilon$ proving that $\{f(x_n)\}$ is Cauchy, and hence convergent. Let $g(a) = \lim f(x_n)$. Do a similar argument to get $g(b)$. Then for $x \in (a,b)$ just set $g(x) = f(x)$. This definition of $g$ will lead to the extension $g$ you want.  
