当前位置:网站首页>JS foundation 2
JS foundation 2
2022-06-28 10:53:00 【Programmer community】
function : Encapsulation of a piece of code , It is mainly used to realize a certain function ( Function is the embodiment of code encapsulation and reuse )
Definition
declarative function Function name (){ The body of the function } call : Function name ()
notes : Functions do not actively execute , Need to call
expression let|var Function name =functtion(){ The body of the function } call : Function name ()
notes : Declarative calls can be made before a function is defined , Expressions cannot
Definition of functions with parameters
Implement known data function code
In the parentheses that define the function , Fill in formal parameters , Multiple are separated by commas
Fill in the arguments in the parentheses of the calling function
Relationship between formal and actual parameters
Formal and actual parameters are in number , The order , Data types should be consistent
If the argument is less than the formal parameter , The parameter value is undefined
Variable scope
Global variables : Global availability . The function passes through var Defined , Or variables defined directly without keywords inside the function body
local variable : Variables defined inside a function body
The return value of the function
When you need the result of the function for the next operation , The return value is required when the return is explicitly required function Function name (){ The body of the function return Variable , value , expression ;} call : Function name ()
notes :return Once executed , Later code will not be executed ,
Function if not return, So the return value of the function is underfined
precompile
Function before line by line execution , Will precompile first
Variable Promotion : Promote the code declared by the variable to the front of the scope
- var Variables defined
- Declaratively defined functions
- return Subsequent statements
- if Inside the sentence ( Even if the conditions don't hold , It will also increase the variable )
arguments
- Function's own object : Record the correlation of function parameters
- Get the number of function arguments arguments.length
- Get a specific argument arguments[ The index of the corresponding argument ]
notes : Index from 0 Start
Recursive function
Recursive function : The function calls itself
notes : Recursion must have an end
Common events
- Get element node
document.getElementById('id name ') - Get element properties
Element nodes . Property name - Set element properties
Element nodes . Property name = Property value - The binding event
Element nodes .on Event type =function (){ To execute code }
Common event types
| event | meaning |
|---|---|
| onclick | Click on |
| onlode | Page loading complete |
| onmouseover | Mouse hovering |
| onmouseout | Mouse removal |
边栏推荐
猜你喜欢

How does ETF position affect spot gold price?

Interface automation framework scaffold - use reflection mechanism to realize the unified initiator of the interface
![[practice] appium settings app is not running after 5000ms](/img/3c/5a7544561231a15a4bb5cfa9e102b3.png)
[practice] appium settings app is not running after 5000ms

JS基础8

An idea plug-in that automatically generates unit tests, which improves the development efficiency by more than 70%!

Realization of a springboard machine

Oracle 日期格式化异常:无效数字

sentinel

使用 ABAP 操作 Excel 的几种方法

利用soapUI获取freemarker的ftl文件模板
随机推荐
ruoyi集成积木报表(nice)
Bytecode proof in appliedzkp zkevm (9)
Oracle 日期格式化异常:无效数字
阿里三面:LEFT JOIN关联表中用ON还是WHERE跟条件有什么区别
Metersphere implements UI automation elements that are not clickable (partially occluded)
Fabric. How to use js brush?
How to use output in katalon
Six fusion positioning technologies in wireless communication application of Internet of things
JSON模块、hashlib、base64
Hystrix deployment
Installing MySQL database (CentOS) in Linux source code
JS基础6
MytipartFile与File的相互转换
【功能建议】多个工作空间启动时选择某个空间
JSON module, hashlib, Base64
sentinel
2D code generator for openharmony application development
Katalon当中的output使用方法
Secretary of the Ukrainian national security and National Defense Commission: will carry out precision strikes against targets in Russia
Fastposter v2.8.4 release e-commerce poster generator