Most authors define functions this way:
Given the sets $A$ and $B$. A relation is a subset of $A\times B$. Then given a relation $R$, we define $Dom_R=\{x|(x,y)\in R\}$ and $Img_R=\{x|(y,x)\in R\}$.
Then a function from $A$ to $B$, $f:A\rightarrow B$, is a relation with the property that each element of the domain is related to exactly one element of the image, such that $Dom_f=A$ and $Img_f\subseteq B$.
Well, if we accept those definitions, functions are just special sets of ordered pairs (remember, functions are relations and, as far as I know, this is emphasized in most books). Specifying the set of inputs and the set of outputs is just necessary when describing functions using the axiom of replacement of ZFC, but what really dictates which set is which is its elements. Thus, for example, the function \begin{align}f:\{0,1\}&\rightarrow \mathbb{R}\\0&\mapsto2\\1&\mapsto 3\end{align} and the function \begin{align}g:\{0,1\}&\rightarrow \{2,3\}\\0&\mapsto2\\1&\mapsto 3\end{align} are the same, since both are the set $\{(0,2),(1,3)\}$. The thing is that $g$ is considered a surjection while $f$ is not. And this is really a problem.
Furthermore, the concept of a graph of a function $Gr(f)$, which is the set $\{(x,f(x))|x\in Dom_f\}$, loses its sense, since the graph would be the function itself.
Wouldn't be much better to define the function as an ordered triple $(A,B,f)$, where $A$ is the domain, $B$ the codomain and $f$ the relation with the properties described above? It's different, since $f$ itself would not be a function, but only the ordered triple would. Then we could define $Gr((A,B,f)):=f$. In this case, the graph of the function would be a relation instead of the function. Also, the notation $f:A\rightarrow B$ could still be used to describe $(A,B,f)$.
To force the function to be a relation, we would have to define relation the same way: the relation would also be an ordered triple $(A,B,R)$, where $R \subseteq A\times B$. But in this case, the relation is not a set of ordered pairs, but the 'graph of the relation' is.
The third and last option is to define both relation and function as a set of ordered pairs, as usually. But although injectivity is a property of a function, surjectivity would rather be a relation between a function $f$ and another given set $B$ called codomain.
Am I getting it right? If so, what is the best way to define a function? Define a function not as a relation but a triple or define a relation not as a set of ordered pairs but a triple? Or another option?