I am following a course in functional analysis and in the introductory chapter on Hilbert spaces, orthogonal projections where introduced like this.
Let $Y$ be a closed subspace of $H$, then $H$ has an orthogonal decomposition $H = Y \oplus Y^\perp$, where $Y^\perp$ is the orthogonal complement of $Y$. This means that for all $h \in H$, there exist unique $h_1 \in Y, h_2 \in Y^\perp$ such that $h = h_1 + h_2$. We call the mapping $\pi_Y: H \rightarrow Y$ defined by $\pi_Y(h) = h_1$ the orthogonal projection onto the subspace $Y$.
This I understand perfectly well. However, we also study projections onto sets, rather than closed subspaces. Say the projection $P$ which projects onto some set $B \subset H$. How should I interpret the action of $P$ on some element $h$ of the Hilbert space? The book does not pay attention to this.
There is a more general result, which says that if $B$ is a closed convex set and $h\in H$, then there exists a unique $b\in B$ such that $\|h-b\|=\operatorname{dist}(h,B)$. This allows you to define $Ph=b$. This $P$ is an idempotent, and sometimes called the projection onto $B$.
When $B$ is a closed subspace, this gives you the projection onto $B$ in the sense you described.