What's the correct way to define a function? (codomain and surjectivity) Here's a common definition of a function (for example, Wiki follows this definition):

A relation between sets $A$ and $B$ is any subset $R \subseteq A \times B$.  We say that this relation is a function if it satisfies the property
  $$
(a,b_1) \in R \text{ and }(a,b_2) \in R \implies b_1 = b_2
$$

This definition of a function is good for most purposes.  Certainly, we can find the domain and range of a function defined in this way.  This also allows us to answer such questions as 

Is the set $\{(1,2),(2,5),(3,5)\}$ a function? (answer: yes)

With such a definition, we could certainly go on to define a function's domain and range. The problem with this definition, however, is that it includes no notion of a codomain.  This presents a problem when we want to answer a question such as

Are the functions $f:\Bbb R \to \Bbb R$ given by $f(x) = x^2$ and $g:\Bbb R \to [0,\infty)$ given by $g(x) = x^2$ the same function?  (answer: no)

On the one hand, the "graphs" of the function are the same.  If we are to believe that these functions are merely subsets of a Cartesian product, then we should say that $f = g$ since both are merely the set $\{(x,x^2) : x \in \Bbb R\}$.  On the other hand, we would like to say that "the function $g$ is surjective, but the function $f$ is not".  If surjectivity is a property of functions, then the fact that $f$ and $g$ do not share this property should mean that $f \neq g$. 
So what gives?   Is there a setting in which both of these questions are well-posed?  If someone has a reference that handles all this well, I would appreciate it.

Edit: Wiki apparrarently has a discussion of this issue here
 A: Forget about functions for a minute and go back to the definition of a relation.
A relation between a first set $A$ with a second set $B$ is any subset of $A \times B$. The set $A$ is called the domain of the relation and the set $B$ is called the codomain. 
By definition, when you look at any relation $\tau$, it is not just a subset of a cartesian product. You have a map,
Domain($\tau$) = $A$ 
Codomain($\tau$) = $B$
Part of the definition/structure of a relation is this underlying concept of domain and codomain. You can't 'forget it'.
If you have any function $f$ between $A$ and $B$ you can define a new function between $A$ and $f(<A>)$. This is now a surjective function. What do you want to call this function. If there is no danger of getting into trouble, how about $f$?. 
So this is part of the definition. If you want you can say,
Consider the 'functional graph' of $y = x^2$ in $\Bbb R \times \Bbb R$.
or
Consider the 'functional graph' of $y = \sqrt x$ in $\Bbb R \times \Bbb R$.
Depending on your audience this might be fine and nobody will get bent out of shape worried about domains and codomains. See wikipedia Codomain; you can 'blame' Nicolas Bourbaki for this. 
A: Upon closer reading, I've found out how the text I'm teaching from resolves this paradox. 
Indeed, a function is considered equal to its graph.  Rather saying that a function is inherently surjective/onto, the text opts to define the phrase $f$ is "onto $B$" to mean that $f$ is surjective when $B$ is taken as the codomain. If we establish a codomain by writing $f:A \to B$, then "onto/surjective" means "onto $B$".
So, there is indeed a valid framework.  We do forego the notion that surjectivity is a property of a function, but I think this is a reasonable compromise.
