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

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

通信原理——纠错编码 | 汉明码(海明码)手算详解

feign调用不通问题,JSON parse error Illegal character ((CTRL-CHAR, code 31)) only regular white space (r

this points to the problem
![[swagger close] The production environment closes the swagger method](/img/43/17be22626ba152b33beaf03f92fbec.png)
[swagger close] The production environment closes the swagger method

Linux修改MySQL数据库密码

The latest MySql installation teaching, very detailed

UiBot has an open Microsoft Edge browser and cannot perform the installation

Yuan prospect and four track of the universe

阿里一面,说说你知道消息中间件的应用场景有哪些?
随机推荐
npm WARN config global `--global`, `--local` are deprecated. Use `--location解决方案
The MySQL database in Alibaba Cloud was attacked, and the data was finally recovered
2021 Mianjing - Embrace Change
MySQL高级学习笔记
Judgment of database in SQL injection
小米手机短信定位服务激活失败
[Cloud native] Simple introduction and use of microservice Nacos
Android software security and reverse analysis reading notes
安装Multisim出现 No software will be installed or removed解决方法
cocoscreator 显示刘海内容
SQLite 查询表中每天插入的数量
Tencent Cloud Lightweight Server deletes all firewall rules
UiBot存在已打开的MicrosoftEdge浏览器,无法执行安装
js中的this指向与原型对象
一个简单的bash转powershell案例
2021面经-拥抱变化
MySQL compressed package installation, fool teaching
quick-3.5 ActionTimeline的setLastFrameCallFunc调用会崩溃问题
The feign call fails, JSON parse error Illegal character ((CTRL-CHAR, code 31)) only regular white space (r
Android软件安全与逆向分析阅读笔记