当前位置:网站首页>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.
边栏推荐
猜你喜欢

mac10.14中安装mysqldb

为什么bash中的read要配合while才能读取/dev/stdin的内容

What is GameFi?

js中的对象与函数的理解
![[JVM Loading]---Class Loading Mechanism](/img/b6/d1754cb6699d18602ca9a463571c0c.png)
[JVM Loading]---Class Loading Mechanism

DeFi Token in the project management

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

UiBot存在已打开的MicrosoftEdge浏览器,无法执行安装

(Crypto essential dry goods) Detailed analysis of the current NFT trading markets
![[Cloud Native] What should I do if SQL (and stored procedures) run too slowly?](/img/40/be3a30743ee2bc6c82f82ab852f29c.png)
[Cloud Native] What should I do if SQL (and stored procedures) run too slowly?
随机推荐
Error: Cannot find module 'D:\Application\nodejs\node_modules\npm\bin\npm-cli.js'
powershell统计文件夹大小
一文速学-玩转MySQL获取时间、格式转换各类操作方法详解
C language tutorial (2) - printf and data types that come with c
Pure shell implementation of text replacement
网页截图与反向代理
【uiautomation】微信好友列表获取(存储到txt中)
Markdown 帮助文档
[Cloud native] Simple introduction and use of microservice Nacos
Using IIS10 to build an asp website in win11
MySQL面试题大全(陆续更新)
场效应管 | N-mos内部结构详解
Powershell中UTF-8环境中文乱码解决办法
GUCCI, LV and other luxury giant universe how to layout yuan, other brands should keep up with?
cocos2d-x-3.2创建项目方法
[Cloud Native] What should I do if SQL (and stored procedures) run too slowly?
通信原理——纠错编码 | 汉明码(海明码)手算详解
UiBot has an open Microsoft Edge browser and cannot perform the installation
【windows】--- SQL Server 2008 超详细安装教程
Understanding SSRF, this article is enough