当前位置:网站首页>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
}
})()
边栏推荐
- OpenSSL的SSL/BIO_get_fd
- 聊聊支付流程的設計與實現邏輯
- Leetcode 108 converts an ordered array into a binary search tree -- recursive method
- As soon as we enter "remote", we will never regret, and several people will be happy and several people will be sad| Community essay solicitation
- [set theory] order relation: summary (partial order relation | partial order set | comparable | strictly less than | covering | hasto | total order relation | quasi order relation | partial order rela
- [combinatorics] generating function (shift property)
- 数学公式(测试)
- [combinatorics] generating function (commutative property | derivative property | integral property)
- [combinatorics] recursive equation (case where the non-homogeneous part is exponential | example where the non-homogeneous part is exponential)
- Three gradient descent methods and code implementation
猜你喜欢
Embedded-c language-7
Research Report on investment trends and development planning of China's thermal insulation material industry, 2022-2028
Codeforces Round #803 (Div. 2) C. 3SUM Closure
Global and Chinese health care OEM and ODM market status survey and investment planning recommendations report 2022-2028
win32:堆破坏的dump文件分析
PHP MySQL preprocessing statement
Introduction to SolidWorks gear design software tool geartrax
(8) HS corner detection
Internet Hospital his Management Platform source, online Inquiry, appointment Registration Smart Hospital Small program source
As soon as we enter "remote", we will never regret, and several people will be happy and several people will be sad| Community essay solicitation
随机推荐
Research Report on investment trends and development planning of China's thermal insulation material industry, 2022-2028
Baiwen.com 7 days Internet of things smart home learning experience punch in the next day
c# . Net tool ecosystem
QT learning diary 9 - dialog box
1146_ SiCp learning notes_ exponentiation
The difference between i++ and ++i: tell their differences easily
【统信UOS】扫描仪设备管理驱动安装
[combinatorics] generating function (property summary | important generating function)*
[tutorial] build your first application on coreos
Win32: dump file analysis of heap corruption
A. Berland Poker & 1000 [simple mathematical thinking]
[Yu Yue education] family education SPOC class 2 reference materials of Shanghai Normal University
Applet with multiple tabs and Swipers + paging of each tab
小程序 多tab 多swiper + 每个tab分页
Wechat applet for the first time
Embedded-c language-7
Solve the problem of inaccurate network traffic monitored by ZABBIX with SNMP
数学公式(测试)
Leetcode 538 converts binary search tree into cumulative tree -- recursive method and iterative method
A. Odd Selection【BruteForce】