This question is about the definition of a function. So let's define a lot of things.
Preliminary
Suppose $X$ and $Y$ are sets and $R\subset X\times Y$. Then we say $R$ is a relation between $X$ and $Y$. We also say that $X$ is a source for $R$ and $Y$ is a target for $R$. Note that any set $X'$ with $X\subset X'$ is also a source for $R$ and any set $Y'$ with $Y\subset Y'$ is also a target for $R$. So the source and target spaces are not unique when looking at $R$ on its own.
We define \begin{align*} \text{Dom}(R) =& \{x\in X:\exists y(y\in Y\land (x, y)\in R)\}\\ \text{Img}(R) =& \{y\in Y:\exists x(x\in X\land (x, y)\in R)\}. \end{align*} Clearly $\text{Dom}(R)\subset X'$ if $X'$ is any source for $R$ and $\text{Img}(R)\subset Y'$ if $Y'$ is any target for $R$.
The relation $R\subset X\times Y$ is functional if for each $x\in X$ and $y, y'\in Y$ if $(x, y), (x, y')\in R$ implies $y=y'$. If $R$ is functional and $(x, y)\in R$ then we can introduce the notation $R(x)=y$.
We are now in a position to define a function in one of two ways.
One Definition of a Function
One definition of a function is that any functional relation is a function. If $f$ is a functional relation then we denote this by \begin{align*} f: \text{Dom}(f) \to Y \end{align*} where $\text{Img}(f)\subset Y$.
Another Definition of a Function
Suppose $X$ and $Y$ are sets and $R\subset X\times Y$ is a relation between $X$ and $Y$. We can define the triple \begin{align*} R_T = (X, Y, R). \end{align*} For lack of a better name, we call $R_T$ the relation tuple, by contrast with $R$ which is the relation. In the context of the relation tuple we say $X$ is the source, $Y$ is the target, and $R$ is the relation graph. If $R$ is a functional relation then we say $R_T$ is a partial function.
Suppose $R_T = (X, Y, R)$ is a relation tuple. If $X = \text{Dom}(R)$ then we say $R_T$ is a total relation tuple.
if $f_T = (X, Y, f)$ is a total partial function then we say $f_T$ is a function and denote this by \begin{align*} f:X\to Y \end{align*}
Discussion
The most important thing I want to point out is that we sometimes hear that a function is a relation that is functional and total. But in the discussion above it is clear that we cannot even define what it means for a relation to be total by looking at the relation. We must explicitly specify a set $X$ with respect to which a relation $R$ either is or is not total.
I think this introduces the possibility for a lot of ambiguity. For example, someone might say $R\subset X\times Y$ is a total relation if $\text{Dom}(R) = X$. But it is also the case that $R\subset X'\times Y$. Is $R$ a total relation now? A rebuttal would be that this English text is implicitly assuming the definition of a 3-tuple $R_T = (X, Y, R)$ and stating that the relation tuple is total. But this is a lot of implicit action going on under-the-hood. Not to mention that to be rigorous with use of the relation/function-tuple is pretty painful in text and authors often abuse notation by treating $R$ and $R_T$ as the same thing, when they aren't.
Using the relation tuple notation it is possible for two functions with the same graph to be unequal. For example, if $X\subset X'$ then it is possible for $(X, Y, f)$ to be total but $(X', Y, f)$ is not total.
Surjectivity is the same as total. We can't tell if a bare relation $R\subset X\times Y$ is surjective. Rather, we need to explicitly indicate the set with respect to which $R$ is surjective or not. If $R_T = (X, Y, R)$ is a relation tuple then $R_T$ is surjective if $Y = \text{Img}(R)$. But all of the same ambiguities crop up again.
I like the first definition because it doesn't open the door to these ambiguities and the temptation of abusing notation by equating a function or relation with its function/relation tuple.
If you want to say a relation is total then you can say $R$ is total on $X$ to mean $X = \text{Dom}(R)$. If you want to say a relation is surjective then you can $R$ is surjective onto $Y$ to mean $Y=\text{Dom}(R)$. If you want to say a function is a bijection then you can say $f$ is a bijection between $X$ and $Y$ to mean $X=\text{Dom}(f)$ and $Y=\text{Img}(f)$.
If you rigorously use the first definition you will probably have to spend more time in English text spelling out which source and target domains matter to you. If you rigorously use the second definition you have have to spend a bit of time juggling between the function/relation tuple and the function/relation graph. I think many texts sort of ambiguously sit between the two definitions letting the relevant source and target sets be implicitly identified.