Some people use the definition of function along these lines:
A function from $X$ to $Y$ is an ordered triple $(X,f,Y)$, where $f\subseteq X\times Y$ and for each $x\in X$ there is unique $y\in Y$ fulfilling $(x,y)\in f$.
(Some examples of texts using this definition can be found if you try to search for function ordered triple or something similar in Google Books.)
This is basically the same thing as saying:
We consider two functions $f\colon X\to Y$, $g\colon Z\to W$ to be equal if (and only if) $X=Z$, $Y=W$ and $f(x)=g(x)$ for each $x\in X$.
So for two functions to be equal, they need to have the same codomain.
(A reasonable search query to find some text including this might be "two functions" equal.)
There are many situations where this distinction is unimportant, so the functions $\sin \colon \mathbb R \to \mathbb R$ and $\sin \colon \mathbb R \to [-1,1]$ are often consider the same. (And the are the same according the definition in the OP. If we use the definition as "function is a subset of $X\times Y$ such that...", then a function is indeed equal to its graph.)
But there are also situations where the distinctions is important, for example speaking about surjective functions only makes sense if you specify the codomain. (So if you use the definition from the OP, you would have to consider surjectivity as property of the pair $(f,Y)$, i.e. a function and a set containing the range of this function, rather then a property of the function $f$.)
Wikipedia article also has a section on alternative definitions of a function. Just in the case the article will be reorganized in the future, I am also adding a link to the current revision.