You should put your function inside a variable so that you can access it like object.
var toggleVis = (function() {
return {
showSomething : function () {
console.log("showSomething");
},
hideSomething : function () {
console.log("hideSomething");
}
};
}());
toggleVis.showSomething();
Will print:
showSomething
To call a function inside that function, make it like this:
var toggleVis = (function() {
return {
showSomething : function () {
console.log("showSomething");
this.hideSomething();
},
hideSomething : function () {
console.log("hideSomething");
}
};
}());
toggleVis.showSomething();
That will print:
showSomething
hideSomething
In this case, this
is referred to the toggleVis
.