If you declare getSelText as var , it should appear before any statements in which you use it. Just make the var getSelText = ... statement the first statement in the run function.
Additional Information:
Operators
var in Javascript "rises" to the top of the function in which they are declared, so this is:
function() { var a = 42;
really means the following:
function() { var a = 42, b;
Another similar construct in Javascript is a function statement, as opposed to function expressions:
function() { var fn1 = function() { return fn2(); };
If you run the code above, it will successfully warn "Hello from fn2". This is because function statements rise to the top to any other operator within the scope in which they are declared. As you can see, this can become very confusing. Probably the best deal is to use function expressions and declare them in the order you need.
source share