当前位置:网站首页>Self executing function
Self executing function
2022-07-03 17:58:00 【Yellow sauce!】
/*
Self executing functions
+ Immediate execution function
+ That is, the function calls itself , After the function declaration , I will execute it immediately
+ characteristic :
=> When the function is finished , It will be destroyed in the memory space , Save space than ordinary functions
=> When we use self executing functions , Will form a private scope , Only for internal use , It can't be used in other places outside
+ effect :
=> Suitable for doing some page initialization things
=> Suitable for making page file modules , Prevent conflict problems
+ Page modular history
=> The technology was not mature before , The front end is just in its infancy , There is no better module solution , There are many back-end personnel also doing the front-end
=> People are in the process of development , I found that the front end didn't even feel special about the module low, So they worked together , It is proposed to use self executing functions as modules
=> Self executing functions do front-end module business , Use for seven or eight years , It was not until its own module appeared in the front end that it was gradually not used
+ Be careful :
=> When the self executing function is connected with another bracket, an error will be reported , I will execute two sentences of code as one sentence
=> Set a semicolon in front of our self executing function , Can solve this problem
*/
// Recommend this style of writing
// (function(){
// console.log(' I'm a self executing function , to see somebody for the first time , Please understand !')
// })()
// function fn(){
// console.log(123)
// }
// fn()
// console.log(fn)
// let fn = (function(){
// console.log(123)
// })()
// console.log(fn)
// Self executing functions can also be written like this
// (function(){
// console.log('hello')
// }())
console.log(' This is a function ')
;(function(){
console.log(' Self executing functions ')
})()
Page function module
<script src="js/a.js"></script>
<script src="js/b.js"></script>
<script>
// Be careful 1: If using let Declared variables , If the variable names are the same , Will report a mistake , Say we num Variables have been declared
// console.log(num)
// Be careful 2: If using var Declared variables , If the variable names are the same , The back will cover the front
console.log(modA.num)
console.log(modB.num)
modA.slider()
modB.cart()
</script>
a.js
;(function () {
console.log(' This is the carousel map module ')
// Custom subscript
let num = 0
// var num = 0
function slider() {
console.log(' This is the business logic code of the rotation chart ')
}
// We can use what we need for the outside world , Can be placed in window On
window.modA = {
num,
slider
}
})()
b.js
;(function () {
console.log(' This is the shopping cart module ')
// Custom subscript
let num = 1
//var num = 1
function cart() {
console.log(' This is the logic code of shopping cart ')
}
window.modB = {
num,
cart
}
})()
边栏推荐
- Three gradient descent methods and code implementation
- 聊聊支付流程的设计与实现逻辑
- The third day of writing C language by Yabo people
- Fedora 21 installs lamp host server
- Keepalived 设置不抢占资源
- Market demand survey and marketing strategy analysis report of global and Chinese pet milk substitutes 2022-2028
- Vs2013 has blocked the installer, and ie10 needs to be installed
- Redis core technology and practice - learning notes (11): why not just string
- Graduation summary
- MinGW compile boost library
猜你喜欢
基于人脸识别的课堂考勤系统 tkinter+openpyxl+face_recognition
MySQL has been stopped in the configuration interface during installation
Type conversion, variable
win32:堆破壞的dump文件分析
Embedded-c language-7
Interviewer: why is the value nil not equal to nil?
一入“远程”终不悔,几人欢喜几人愁。| 社区征文
Internet Hospital his Management Platform source, online Inquiry, appointment Registration Smart Hospital Small program source
Redis core technology and practice - learning notes (VI) how to achieve data consistency between master and slave Libraries
网格图中递增路径的数目[dfs逆向路径+记忆dfs]
随机推荐
图像24位深度转8位深度
The second largest gay dating website in the world was exposed, and the status of programmers in 2022
On Data Mining
[combinatorics] generating function (property summary | important generating function)*
自动渗透测试工具核心功能简述
Research on Swift
PHP MySQL where clause
Supervisor monitors gearman tasks
WEB-UI自动化测试-最全元素定位方法
MySQL grouping query
Ssl/bio of OpenSSL_ get_ fd
ES6类的继承
How to install PHP on Ubuntu 20.04
[combinatorics] generating function (commutative property | derivative property | integral property)
Distributed task distribution framework gearman
Brief introduction to the core functions of automatic penetration testing tool
Draw some simple graphics with MFC
解决Zabbix用snmp监控网络流量不准的问题
SDNUOJ1015
Automata and automatic line of non-standard design