Skip to content

Instantly share code, notes, and snippets.

@josephj
Created September 8, 2012 11:59
Show Gist options
  • Save josephj/3674198 to your computer and use it in GitHub Desktop.
Save josephj/3674198 to your computer and use it in GitHub Desktop.
mods[“ykpsb”] = function () {
// 利用闭包与外界隔绝
var privateVar,
publicFn;
// 内部自行处理,不会影响其他模块
privateVar = "123";
publicFn = function () {};
return {
// 仅揭露需公开的方法
publicFn: publicFn
};
}();
// 外界仅可存取公开方法
mod["ykpsb"].publicFn();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment