Last active
August 29, 2015 14:13
-
-
Save auramo/7cac7f6056939ddc86a6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var myUtil = (function() { | |
function doStuffToDate(date) {} | |
... | |
return { doStuffToDate: doStuffToDate, //other public funcs } | |
})(); | |
myUtil.doStuffToDate(date); //use | |
var dstd = myUtil.doStuffToDate; //"import" | |
//You can also "inline" the implementations if they're short | |
var myUtil = (function() { | |
function somePrivateFuncNotVisibleToOutSide() {...} | |
... | |
return { doStuffToDate: function(date) {...}, | |
//other public funcs | |
} | |
})(); | |
//"dotted namespace" | |
var my = {} | |
my.util = (function() { | |
function somePrivateFuncNotVisibleToOutSide() {...} | |
... | |
return { doStuffToDate: function(date) {...}, | |
//other public funcs | |
} | |
})(); | |
// ^ Beware of defining my twice if you have my.something in many places | |
// You can protect against that with this ugliness: | |
if (typeof(my) === 'undefined') { | |
var my = {} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment