当前位置:网站首页>function in js
function in js
2022-07-31 05:59:00 【messy me】
A function in JavaScript is also an object. Some functions (code) can be encapsulated in the function, and these functions (code) can be executed when needed.The function can save some code to be called when needed.
function function:- A function is also an object, some functions can be encapsulated in the function, and these functions can be executed when needed.- Functions can save some code to be called when needed. When using typeof to check a function object, it will return function.Creates a function object that can pass the code to be encapsulated as a string to the constructor.Code wrapped into a function does notExecute immediately, the code in the function will be executed when the function is called.Call function syntax: function object()Such as: var fun = new function(){console.log(1)};fun()The output result is 1;When a function is called, the code encapsulated in the function is executed in internal code order.Create function: use function declaration, function expression to create:
function declaration syntax:function function name([parameter1, parameter2....parametern]){statement...}Use function expressions to create a functionvar function name = function([parameter 1, parameter 2....parameter n]){Statement....}Formal parameters of the function:
Formal parameters of the function:One or more formal parameters (formal parameters) can be specified in () of a function.Used between multiple formal parameters, separated.Declaring a formal parameter is equivalent to declaring the corresponding variable inside the function.But don't assign a value to it.like:function sum(a,b){console.log(a+b);} is equivalent tofunction sum(a,b){var a; var b ;console.log(a+b);}When calling a function, you can specify arguments (actual parameters) in ().The actual parameter will be assigned to the corresponding formal parameter in the function.like:sum(1,2) where a and b are formal parameters.1 and 2 are the corresponding actual parameters.The calling function is a parser and does not check the type of the arguments.So you need to check some illegal parameters when using it.The parser also doesn't check the number of arguments when calling the function.Such as sum(1,2,h,o).During use, redundant arguments will not be assigned.If the number of actual parameters is less than the number of formal parameters, then the formal parameters without corresponding actual parameters will be undefinedExecute the function immediately:
function object()Immediately execute the function. After the function is defined, it is called immediately. This kind of function is called an immediate execution function.Immediate functions tend to be executed only once.like:(function(a,b){console.log("a="+a);console.log("b="+b);})(1,2);The output result is a=1, b=2.Method:
The properties of an object can be any value, as well as a function.If a function is saved as a property of an object, then we call the function a method of the object, and calling the function is said to call the method of the object.It's just a name change.It is no different from other functions.
边栏推荐
- 【Elastic-Job】分布式调度任务概览篇
- 安装Multisim出现 No software will be installed or removed解决方法
- 著名网站msdn.itellyou.cn原理分析
- CMOS管原理,及其在推挽电路中的应用
- Using IIS10 to build an asp website in win11
- quick-3.5 ActionTimeline的setLastFrameCallFunc调用会崩溃问题
- UiBot has an open Microsoft Edge browser and cannot perform the installation
- kotlin 插件更新到1.3.21
- 【JVM加载】---类加载机制
- 常见JVM面试题及答案整理
猜你喜欢
随机推荐
计网 Packet Tracer仿真 | 简单易懂集线器和交换机对比(理论+仿真)
Several solutions for mysql startup error The server quit without updating PID file
C语言 | 获取字符串里逗号间隔的内容
阿里一面,说说你知道消息中间件的应用场景有哪些?
cocos2d-x-3.2 不能混合颜色修改
Common JVM interview questions and answers
使用ps | egrep时过滤排除掉egrep自身
[uiautomation] Get WeChat friend list (stored in txt)
浅谈对分布式模式下CAP的理解
[swagger close] The production environment closes the swagger method
数字孪生将成为进入“元宇宙”一项重要的途径
对js的数组的理解
powershell statistics folder size
What is an EVM Compatible Chain?
5 methods of MySQL paging query
MySQL分页查询的5种方法
The feign call fails, JSON parse error Illegal character ((CTRL-CHAR, code 31)) only regular white space (r
NFTs: The Heart of Digital Ownership
[Ubuntu20.04 installs MySQL and MySQL-workbench visualization tool]
360 加固 file path not exists.






![[Elastic-Job source code analysis] - job listener](/img/99/5e047b1aa83aad7d7f17b4eec606e6.png)

