Don't use a function() directly, use a function that creates the onclick function:
<html>
<head>
<script>
function share(it) {
alert("We wanted 1, we got "+ it);
}
function makeFunction(x) {
return function() {share(x);}
}
</script>
</head>
<body>
<span id="key">Click me</span>
<script>
var x = 1;
document.getElementById('key').onclick = makeFunction(x)
x++;
</script>
</body>
</html>