Russ Bradberry
Russ Bradberry

Reputation: 10865

Making a Method Globally Accessible in Javascript

given i have the following block of code

(function(){    
    var mb = {
        abc:function(){
            //do something
        },
        xyz:function(width, height, site){
            //do something
        }
    };
})();

how do i make the method mb.abc accessible from the page, but not mb.xyz?

Upvotes: 1

Views: 215

Answers (1)

psychotik
psychotik

Reputation: 39019

var mb = function() {
    function xyz(width, height, site){
        // not visible outside
    }

    return {
        abc:function(){
            //do something
        }
    };   
}();

mb.abc() is public, but mb.xyz() is not.

Upvotes: 5

Related Questions