当前位置:网站首页>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.
边栏推荐
- 2021 Mianjing - Embrace Change
- SSH自动重连脚本
- Hyper-V新建虚拟机注意事项
- 为什么bash中的read要配合while才能读取/dev/stdin的内容
- Markdown 帮助文档
- 小米手机短信定位服务激活失败
- Several forms of Attribute Changer
- Regular Expression Basics
- The feign call fails, JSON parse error Illegal character ((CTRL-CHAR, code 31)) only regular white space (r
- 腾讯云GPU桌面服务器驱动安装
猜你喜欢

Linux修改MySQL数据库密码
![[Ubuntu20.04 installs MySQL and MySQL-workbench visualization tool]](/img/3d/1b65fb33bfbf22da8243df1ab33ed5.png)
[Ubuntu20.04 installs MySQL and MySQL-workbench visualization tool]

安装Multisim出现 No software will be installed or removed解决方法

MySql创建数据表

The MySQL database in Alibaba Cloud was attacked, and the data was finally recovered

On the side of Ali, tell me what are the application scenarios of message middleware you know?

著名网站msdn.itellyou.cn原理分析

Linux中mysql密码修改方法(亲测可用)

MySQL高级SQL语句(二)

js中的全局作用域与函数作用域
随机推荐
数据库 | SQL查询进阶语法
MySQL错误-this is incompatible with sql_mode=only_full_group_by完美解决方案
SQLite 查询表中每天插入的数量
flutter 混合开发 module 依赖
quick-3.5 ActionTimeline的setLastFrameCallFunc调用会崩溃问题
2021面经-拥抱变化
mysql启动报错The server quit without updating PID file几种解决办法
Year-end summary - the years are quiet~
[windows]--- SQL Server 2008 super detailed installation tutorial
MySQL高级SQL语句(二)
Linux中mysql密码修改方法(亲测可用)
【云原生】SQL(及存储过程)跑得太慢怎么办?
sqlmap injection tutorial common commands
年终总结——岁月静好~
为什么redis是单线程还那么快?
cocos2d-x-3.2图片灰化效果
【云原生】微服务Nacos的简单介绍与使用
js中的对象与函数的理解
What is GameFi?
Linux modify MySQL database password