三亩地 三亩地SAN MU DI · CODE DIARY
ARTICLE DETAIL

日记详情

真实记录编程学习的某一天,欢迎挑你感兴趣的翻一翻。

立即执行函数模块化

立即执行函数模块化
(function(window,$){// 数据letdata='I am a module';// 操作数据的函数functionfoo(){console.log(`foo()${data}`);$('body').css('background','red');}functionbar(){console.log(`bar()${data}`);otherFun();//内部调用}// 内部私有函数functionotherFun(){console.log('otherFun()');}//暴露APIwindow.$myModule={foo,bar};})(window,jQuery);
← 返回列表