Consider the code:
function foo()
{
console.log('foo');
}
function bar()
{
var foo = 5;
foo(); // (*)
}
How to make (*) refer to outer function instead of local variable?
If the outer scope is the global scope, you can do
window.foo(); // assuming you're in a browser
If not, then you're out of luck. Give the local variable another name.
An example of when you're out of luck:
window.onload = function() {
function foo()
{
console.log('foo');
}
function bar()
{
var foo = 5;
foo(); // (*)
}
}
The scope of the anonymous "load" handler function has no name, or any other handle by which the code in function "bar" could indicate that it wanted a reference to that "foo" instead of the local one.
Note that Coffeescript explicitly disallows this; it won't allow a local symbol to hide a more global one. (That's a controversial feature of the language, before you jump on the Coffeescript train.)
If your function is global you can use:
window.foo()
More info: http://www.w3schools.com/js/js_function_invocation.asp
requirethe modules as necessary to avoid all scoping ambiguity.function foo()invar otherFoo = {foo: function...resolves your issue, which is what modules do.