The problem here is the scope of the variables a and position, since you have declared them in the function one, it exists only inside that function, once the function is exited the variables are no longer available.
Since you are accessing the variables in function two, you need to declare them in a shared scope like
var position, a;
function one() {
a = 1;
position = {
global: function(b) {
snippet.log('b:' + b);
}
}
}
function two() {
$(window).on('scroll', function() {
one();
position.global(a);
});
}
two();
body {
height: 3000px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!-- Provides the `snippet` object, see http://meta.stackexchange.com/a/242144/134069 -->
<script src="http://tjcrowder.github.io/simple-snippets-console/snippet.js"></script>
Another way to use the variable a is to make use of closure like
var position;
function one() {
var a = 1;
position = {
global: function() {
snippet.log('a:' + a);
}
}
}
function two() {
$(window).on('scroll', function() {
one();
position.global();
});
}
two();
body {
height: 3000px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!-- Provides the `snippet` object, see http://meta.stackexchange.com/a/242144/134069 -->
<script src="http://tjcrowder.github.io/simple-snippets-console/snippet.js"></script>
aandpositionin a shared scope