In this example code:
(function(){
var obj = function() {
};
obj.prototype.hello = function(){
consol
To avoid polluting outer scope. You're sure no variables are going to "get out" of it.
But yes, you do need to export it. Either using window.obj = obj;
from inside (to make it global) or return it :
var obj = (function() {
var obj = function() {};
obj.prototype.sayHello = function() {};
return obj;
})();