チートシートなので説明なし。
JavaScriptでの名前空間の書き方。
var top = top || {}; // ancestor namespace
top.second = top.second || {}; // ancestor namespace
(function (third) { // namespace
// private property
var privPropName = "privPropValue";
// private method
function privFuncName() {
}
// public function
third.funcName = function () {
}
// public class
third.ClassName = (function () {
function ClassName() {
}
return ClassName;
})();
// public singleton object
third.objectName = (function () {
return {
};
})();
})(top.second.third = top.second.third || {});
// usage
top.second.third.funcName();
var instance = new top.second.third.ClassName();
top.second.third.objectName;