Question

Is there any reason you would ever want to call a function defined inside a namespace created using the revealing module pattern using its fully qualified name? For example, A vs. B below?

Example A.

var namespace = (function defineNamespace() {

    function sayNoThankYou() { }

    function callMeMaybe() {
        sayNoThankYou();
    }

    return {
        callMeMaybe: callMeMaybe,
        sayNoThankYou: sayNoThankYou
    };

}());

Example B.

var namespace = (function defineNamespace() {

    function sayNoThankYou() { }

    function callMeMaybe() {
        namespace.sayNoThankYou();
    }

    return {
        callMeMaybe: callMeMaybe,
        sayNoThankYou: sayNoThankYou
    };

}());
Was it helpful?

Solution

There is only one difference between namespace.sayNoThankYou(); and sayNoThankYou(); in your example: the value of this inside the sayNoThankYou function. If you don't use this inside the function, they are identical.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top