Skip to content

Instantly share code, notes, and snippets.

@xuanfeng
Created January 13, 2014 10:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xuanfeng/8397581 to your computer and use it in GitHub Desktop.
Save xuanfeng/8397581 to your computer and use it in GitHub Desktop.
JS 模块化写法
// 匿名函数-实现模块化
(function(){
// 定义对象
var Draw = {};
// 共有方法
Draw.init = function(){};
// 私有方法
Draw._private = function(){};
// 外部接口
window.Draw = Draw;
})();
// 调用模块
(function(win, draw){
window.Draw.init();
})(window, Draw)
@FrankFan
Copy link

还可以试试继承的方式

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment