How is $\{1, x, x^2, x^3, …\}$ a basis for $L^2(-1, 1)$?

I have just read that $\{1, x, x^2, x^3, ...\}$ is a basis for $L^2(-1, 1)$...I don't get this. It seems like that set is a basis for the space of polynomials of degree up to infinity. I don't see how it can be a basis for all square integrable functions?

• Technical point: Is the interval closed or open? – Andrew D. Hwang Nov 15 '15 at 16:30
• As stated where I read it, it is open. – Riggs Nov 15 '15 at 17:14

In the setting of normed linear spaces, a basis spans a dense subspace. To say the monomials constitute a basis of $L^{2}[-1, 1]$ amounts to the assertion that for every function $f$ in $L^{2}[-1, 1]$, there exists a sequence $(p_{n})$ of polynomials such that $$\int_{-1}^{1} |f - p_{n}|^{2} \to 0.$$
The space of continuous functions on $[-1, 1]$ is dense (with respect to the $L^{2}$ norm) in $L^{2}[-1, 1]$ by Lusin's theorem, and the space of polynomials is dense with respect to the sup norm by the Weierstrass approximation theorem, hence dense with respect to the $L^{2}$ norm on $[-1, 1]$. A dense subspace of a dense subspace is a dense subspace, so the monomials are indeed a basis of $L^{2}[-1, 1]$.
If you did mean $L^{2}(-1, 1)$ (open interval), you can use the fact that the space of compactly supported functions in $L^{2}(-1, 1)$ is dense, then use the sketch of the preceding paragraph to see that polynomials are dense in the space of compactly supported $L^{2}$ functions.