Since $B$ is nowhere dense, it inherits the discrete topology from $X$, which means that any function from $B$ will be continuous. Thus any surjection from $\mathbb{Z}$ onto $\mathbb{Q}$ serves as an example.
But we can do better than this. It is actually possible for $f$ to be continuous on all of $X$, with $f(B)$ still dense! Let $X$ be the positive reals, with $f(x)=x\sin(x)$. Define $$B = \bigcup_{n \in \mathbb{N}} \{2\pi n^3 + \sin^{-1}(\frac{k}{n^4}): k \in \mathbb{N}, k < n^2\}. $$ One can see that $B$ is nowhere dense: every interval of length $2\pi$ contains only finitely many points of $B$. To show $f(B)$ is dense, we need to construct a $b \in B$ with $|b\sin(b) - x| < \epsilon$ for any arbitrary $x, \epsilon > 0$. For large $n$, we have that $\frac{1}{n^2} < \frac{\epsilon}{2}$. For larger $n$, there is some integer $k$ for which $|\frac{2\pi k}{n} - x| < \frac{\epsilon}{2}$. For still larger $n$, we also can guarantee that $k < n^2$.
Therefore $B$ contains the point $b = 2\pi n^3 + \sin^{-1}(\frac{k}{n^4})$. Now, $f(b) = b \sin(b) = b \cdot \frac{k}{n^4} = \frac{2\pi k}{n} + \frac{k}{n^4}\sin^{-1}(\frac{k}{n^4})$. Thus,
$$ |b - x|
= \bigg| \frac{2\pi k}{n} + \frac{k}{n^4}\sin^{-1}(\frac{k}{n^4}) - x \bigg|
\leq \bigg| \frac{2\pi k}{n} - x\bigg| + \bigg|\frac{k}{n^4}\sin^{-1}(\frac{k}{n^4}) \bigg|. $$
The first term is less than $\frac{\epsilon}{2}$ by choice of $k$. The second term is also less than $\frac{\epsilon}{2}$, because $\sin^{-1}(\frac{k}{n^4})$ is bounded by 1, and $\frac{k}{n^4} < \frac{n^2}{n^4} = \frac{1}{n^2} < \frac{\epsilon}{2}$. Therefore $|b - x| < \epsilon$.
There are probably better examples than this. This related post offers a hypothesis which, if true, would give a far more elegant example.