当前位置:网站首页>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
}
})()
边栏推荐
- Redis core technology and practice - learning notes (VII) sentinel mechanism
- [LINUX]CentOS 7 安装MYSQL时报错“No package mysql-server available“No package zabbix-server-mysql availabl
- Codeforces Round #803 (Div. 2) C. 3SUM Closure
- ArrayList analysis 3: delete elements
- (9) Opencv Canny edge detection
- [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
- Redis core technology and practice - learning notes (IX): slicing cluster
- Graduation summary
- [tutorial] build your first application on coreos
- Image 24 bit depth to 8 bit depth
猜你喜欢

模块九作业

基于人脸识别的课堂考勤系统 tkinter+openpyxl+face_recognition

Wechat applet for the first time

TCP congestion control details | 3 design space

SQL injection database operation foundation

Five problems of database operation in commodity supermarket system

Records of long objects and long judgments in the stream of list

Tensorboard quick start (pytoch uses tensorboard)

List的stream中Long对象与long判等问题记录

PHP MySQL inserts data
随机推荐
Redis core technology and practice - learning notes (VII) sentinel mechanism
AcWing 271. Teacher Yang's photographic arrangement [multidimensional DP]
[combinatorics] recursive equation (case where the non-homogeneous part is exponential | example where the non-homogeneous part is exponential)
link preload prefetch
OpenSSL的SSL/BIO_get_fd
[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
聊聊支付流程的设计与实现逻辑
PHP MySQL inserts data
Investigation on the operation prospect of the global and Chinese Anti enkephalinase market and analysis report on the investment strategy of the 14th five year plan 2022-2028
Leetcode 669 pruning binary search tree -- recursive method and iterative method
Draw some simple graphics with MFC
i++与++i的区别:通俗易懂的讲述他们的区别
Kotlin's collaboration: Context
Redis core technology and practice - learning notes (IX): slicing cluster
聊聊支付流程的設計與實現邏輯
Wechat applet for the first time
远程办公工具分享|社区征文
Micro service component sentinel console call
Kotlin的协程:上下文
SDNUOJ1015