当前位置:网站首页>JS module, closure application
JS module, closure application
2022-07-27 13:42:00 【Ares-Wang】

------------------------------------------- model ------ block ----------------------------------------------------------------------------
------- A separate myModule1.js file -----------
function myModule1(){
var msg=‘Ares_Wang’ // Private variables
// Functions that manipulate data
function doSomething(){
console.log(‘doSomething()’+msg.toUpperCase())
}
function doSomething(){
console.log(‘doOthing()’+msg.toLowerCase())
}
// Exposed objects ( Methods for external use )
return {
doSomething:doSomething, // ES6 It can be abbreviated doSomething,
doOtherthing:doOtherthing // ES6 It can be abbreviated doOtherthing
}
}
---------------------html- Interface ----------------------------
<script type="text/javascript" src="myModule1.js"></script>
<script> var module=myModule1() // An object module.doSomthing() module.doOtherthing() </script>
--------------------- utilize IIFE— Implementation module -------------------------------------------------
------- A separate myModule2.js file -----------
(function (window){
var msg=‘Ares_Wang’ // Private variables
// Functions that manipulate data
function doSomething(){
console.log(‘doSomething()’+msg.toUpperCase())
}
function doSomething(){
console.log(‘doOthing()’+msg.toLowerCase())
}
// Exposed objects ( Methods for external use )
window.myModule2= {
doSomething:doSomething, // ES6 It can be abbreviated doSomething,
doOtherthing:doOtherthing // ES6 It can be abbreviated doOtherthing
}
})(window)---------------------html- Interface ----------------------------
<script type="text/javascript" src="myModule2.js"></script>
<script> myModule2.doSomthing() myModule2.doOtherthing() </script>
边栏推荐
- Fiddler抓包工具+夜神模拟器
- Differences between shell environment variables and set, env, export
- Can you tell me the difference between lateinit and lazy in kotlin?
- 面试官常问:如何手撸一个“消息队列”和“延迟消息队列”?
- 滑环设备怎么进行维护
- evutil_ make_ internal_ pipe_: pipe: Too many open files
- 双料第一!
- 能说一说 Kotlin 中 lateinit 和 lazy 的区别吗?
- Product manager experience 100 (XI) - Strategic Product Manager: model and methodology
- 以科技传递温度,vivo亮相数字中国建设峰会
猜你喜欢

Seata's landing practice in ant International Banking

【300+精选大厂面试题持续分享】大数据运维尖刀面试题专栏(九)

Li Kou 1480. Dynamic sum of one-dimensional array 383. Ransom letter 412. Fizz buzz

滑环设备怎么进行维护

Interview site: three kinds of questions

3D laser slam:aloam---ceres optimization part and code analysis

SCI thesis writing

51:第五章:开发admin管理服务:4:开发【新增admin账号,接口】;(只开发了【用户名+密码的,方式】;【@T…】注解控制事务;设置cookie时,是否需要使用URLEncoder去编码;)

JS 模块、闭包应用

纵横靶场-图片的奥秘
随机推荐
腾讯云联合中国工联院发布工业AI质检标准化研究成果加速制造业智能化转型
A brief analysis of the four process pools
Feign's overall process
Dichotomy queries values in an array
v-show
Go语言系列:如何搭建Go语言开发环境?
How about the strength of database HTAP
Common types of electric slip rings
Design of network abnormal traffic analysis system
Write a program, accept a string consisting of letters, numbers and spaces, and a character, and then output the number of characters in the input string. Case insensitive.
Redis summary: cache avalanche, cache breakdown, cache penetration and cache preheating, cache degradation
初学者入门:使用WordPress搭建一个专属自己的博客
16-VMware Horizon 2203 虚拟桌面-Win10 自动桌面池完整克隆专用(十六)
evutil_make_internal_pipe_: pipe: Too many open files
网络异常流量分析系统设计
SNMP (Simple Network Management Protocol)
Talk about one of the important classes of feign components, reactivefeign
Can I only use tidb binlog tool to synchronize tidb to MySQL in real time?
字节跳动 AI Lab 总监李航:语言模型的过去、现在和未来
[basic knowledge] ~ IC design process and EDA tools used in each stage