Sheaf of germs of regular functions on an affine variety Let $k$ be an algebraically closed field.
Let $X$ be a Zariski closed subset of $k^n$.
Let $I(X) = \{f \in k[x_1,\dots,x_n]| f(p) = 0$ for every $p \in X\}$.
Let $A = k[x_1,\dots,x_n]/I(X)$.
Let $U$ be an open subset of $X$.
Let $f\colon U \rightarrow k$ be a function.
We say $f$ is regular at a point $p$ of $U$ if there exist an open neighborhood $V$ of $p$ contained in $U$ and $g, h \in A$ such that $h$ does not vanish at every point of $V$ and $f(x) = g(x)/h(x)$ for every $x \in V$.
We say $f$ is regular on $U$ if $f$ is regular at every point of $U$.
Let $\Gamma(U)$ be the set of regular functions on $U$.
Clearly $U \rightarrow \Gamma(U)$ defines a sheaf $\mathcal{O}$ of rings on $X$.
How do we prove the following assertions?
1) Let $x \in X$. $\mathcal{O}_x$ is canonically isomorphic to $A_{m_x}$, where $m_x$ is the maximal ideal of $A$ corresponding to $x$.
2) Let $f \in A$. $\Gamma(D(f))$ is canonically isomorphic to $A_f$, where $D(f) = \{x \in X| f(x) \neq 0\}$.
 A: Following QiL's advice, we translate the Hartshorne's proof of II.2.2 in the language of varieties.
Lemma 1
Let $X$ and $A$ be as in the question.
Let $f \in A$.
Then $D(f)$ is quasi-compact.
Proof:
Suppose $D(f) = \bigcup_{i\in I} U_i$, where $U_i$ is an open subset of $X$.
$U_i$ can be covered by open subsets of the form $D(g)$.
Hence, without loss of generality we may assume that $U_i = D(g_i)$, i.e.
$D(f) = \bigcup_{i\in I} D(g_i)$.
Then $V(f) = \bigcap V(g_i)$.
Let $\mathfrak{a}$ be the ideal generated by $(g_i)_{i\in I}$.
Then $V(f) = V(\mathfrak{a})$.
By Hilbert Nullstellensatz, $\sqrt((f)) = \sqrt(\mathfrak{a})$.
Hence $f^n \in \mathfrak{a}$ for some $n$.
Hence there exists a finite subset $J$ of $I$ such that $f^n \in (\{g_j| j \in J\})$.
Hence $D(f) = D(f^n) \subset D(\{g_j| j \in J\}) = \bigcup_{j\in J} D(g_j)$.
QED
Lemma 2
Let $X$ and $A$ be as in the question.
Let $f, g \in A$.
Suppose $D(f) \subset D(g)$.
Then $f^n \in (g)$ for some $n$.
Proof:
$V(g) \subset V(f)$.
By Hilbert Nullstellensatz, $\sqrt((f)) \subset \sqrt((g))$.
Hence $f^n \in (g)$ for some $n$.
QED
Lemma 3
Let $X$ and $A$ be as in the question.
Let $f, g \in A$.
Suppose $g(x) = 0$ for every $x \in D(f)$.
Then $fg = 0$.
Proof:
$f(x)g(x) = 0$ for every $x \in D(f)$ and for every $x \in X - D(f)$.
Hence $f(x)g(x) = 0$ for every $x \in X$.
Hence $fg = 0$.
QED
1)
Every element of $A$ can be regarded as a regular function on $X$.
Hence there exists a canonical homomorphism $\psi\colon A \rightarrow \mathcal{O}_x$.
Let $f \in A - m_x$.
Then $f(x) \neq 0$.
Hence $\psi(f)$ is invertible in $\mathcal{O}_x$.
Hence, by the universal property of the localization $A_{m_x}$, $\psi$ induces a unique homomopohism $\psi_x\colon A_{m_x} \rightarrow \mathcal{O}_x$ such that $\psi_x(g/f) = \psi(g)/\psi(f)$, where $g,f \in A$ and $f \in A - m_x$.
Clearly $\psi_x$ is surjective.
It remains to prove that $\psi_x$ is injective.
Suppose $\psi_x(g/f) = 0$, where $g, f \in A$ and $f \in A - m_x$.
Since $\psi_x(g/f) = \psi(g)/\psi(f)$, $\psi(g) = 0$.
Hence there exists an open neighborhood $U$ of $x$ such that $g|U = 0$.
There exists $h \in A$ such that $x \in D(h) \subset U$.
Since $g|D(h) = 0$, $hg = 0$ by Lemma 3.
Since $h \in A - m_x$, $g/f = 0 \in A_{m_x}$.
Hence $\psi_x$ is injective as desired.
2)
Every element of $A$ can be regarded as a regular function on $X$.
Hence there exists a canonical homomorphism $\phi\colon A \rightarrow \Gamma(D(f))$.
Since $\phi(f)$ is invertible in $\Gamma(D(f))$, by the universal property of the localization $A_f$, $\phi$ induces a unique homomopohism $\phi_f\colon A_f \rightarrow \Gamma(D(f))$ such that $\phi_f(g/f^n) = \phi(g)/\phi(f)^n$ for $g \in A$ and an integer $n > 0$.
Suppose $\phi_f(g/f^n) = 0$.
Then $g(x) = 0$ for every $x \in D(f)$.
Hence $fg = 0$ by Lemma 3.
Hence $g/f^n = 0 \in A_f$.
Hence $\phi_f$ is injective.
It remains to prove that $\phi_f$ is surjective.
Let $s \in \Gamma(D(f))$.
Then, by definition, we can cover $D(f)$ with a family of open subsets $(D(h_i))_{i\in I}$ such that $s = a_i/g_i$ on $D(h_i)$, where $a_i, g_i \in A$ and $D(h_i) \subset D(g_i)$.
By Lemma 1, we may assume that $I$ is a finite set.
Suppose $D(f) = D(h_1)\cup\cdots D(h_r)$.
By Lemma 2, $h_i^n \in (g_i)$ for some $n$.
Hence $h_i^n = cg_i$ for some $c \in A$. Hence $a_i/g_i = ca_i/h_i^n$.
Since $D(h_i) = D(h_i^n)$, replacing $h_i$ by $h_i^n$ and $a_i$ by $ca_i$ we may assume that $s = a_i/h_i$ on $D(h_i)$. 
Since $V(f) = V(h_1,\dots,h_r)$, $\sqrt{(f)} = \sqrt((h_1,\dots,h_r))$.
Hence $f^n = \sum b_ih_i$ for some $n$.
$s = a_i/h_i = a_j/h_j$ on $D(h_ih_j)$ for all $i, j$.
Hence $h_ja_i - h_ia_j = 0$ on $D(h_ih_j)$.
Hence $(h_ih_j)(h_ja_i - h_ia_j)$ by Lemma 3.
Hence $h_j^2h_ia_i = h_i^2h_ja_j$.
Since $D(h_i) = D(h_i^2)$, replacing $h_i$ by $h_i^2$ and $a_i$ by $h_ia_i$, we get $h_ja_i = h_ia_j$ for all $i, j$.
Then $b_ih_ja_i = b_ih_ia_j$.
Hence $\sum_i b_ih_ja_i = \sum_i b_ih_ia_j$.
Hence $h_ja = f^na_j$, where $a = \sum_i b_ia_i$.
Hence $a/f^n = a_j/h_j$ on $D(h_j)$ for all $j$.
Since $s = a_j/h_j$ on $D(h_j)$, $\phi_f(a/f^n) = s$as desired.
