Ben
Ben

Reputation: 62364

Javascript private variables

How can I make my tabs variable private and only accessible from within the return {}... console.log(tabs) returns undefined...

$(document).ready(function () {
    Site.page = (function () {
        return {
            init: function () {
                Site.page.tabs.init();
            },
            //manage deal tabs
            tabs: (function () {
                var tabs = null;
                return {
                    init: function () {
                        console.log(tabs);
                    },
                    show: function (tab) {
                        $('#deal-tabs > div.selected').removeClass('selected');
                        $(tab).addClass('selected');
                    }
                }
            })()
        }
    }());

    Site.page.init();
});

Upvotes: 0

Views: 391

Answers (1)

Claudiu
Claudiu

Reputation: 3261

Why did you name both the function and the variable the same name? If you only need the variable in return{} then declare it in that block of code, not outside.

Upvotes: 1

Related Questions