当前位置:网站首页>New feature in ES6 -- arrow function
New feature in ES6 -- arrow function
2022-06-11 09:38:00 【Snatch bamboo shoots 123】
Here's the catalog title
Define format
var Function name =( Function parameter )=> Function return value ;
Examples of arrow function usage
// No function arguments
var fun=()=>5;
// amount to
var fun=function(){
return 5
}
// Single function parameter
var pow1 = num => Math.pow(num,2);
var pow1=function(num){
return Math.pow(num,2);
}
// Multiple function arguments
var sum = (num1, num2) => num1 + num2; // amount to var sum = (num1, num2) => {return num1+num2};
var sum=function(num1,num2){
return num1+num2;
}
effect
- Simplify callback functions
//sort Callback function in function
var result = array.sort((a, b) => a - b);
// amount to
var result = array.sort(function (a, b) {
return a - b;
});
Callback function : Is passed as an argument to another parameter and is called in the function , Functions used to complete certain tasks
- Simplify the expression
// Define a tool function to calculate the square value of a number
const pow_1=num=>num**2
pow_1(n)
characteristic
(1) Arrow function does not have its own this object .
(2) Can't be used as a constructor , in other words , You cannot use... For arrow functions new command
(3) Not available arguments object , The object does not exist inside the function .
(4) Not available yield command
Be careful
When the return value of the function is an object , You need to put brackets
var myobj= name => ({
name: "Temp" ,age: 19});
Use example of arrow function
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> This is a html5 demo</title>
</head>
<body>
<script> var num1=1,num2=2 var sum = (num1, num2) => {
return num1+num2}; // var sum = (num1, num2) => num1+num2 var pow_1=num=>num**2 var fun=()=>5; console.log(fun()) console.log(pow_1(num2)) console.log(sum(num1,num2)) </script>
</body>
</html>
Chrome Browser run results 
边栏推荐
- Fabric.js 动态设置字号大小
- [scheme development] sphygmomanometer scheme pressure sensor sic160
- Shandong University project training (IV) -- wechat applet scans web QR code to realize web login
- The first TOF related data set available for deep learning: deep learning for confidence information in stereo and TOF data fusion (iccv 2017)
- ESP8266_SmartConfig
- Set up redis highly available cluster environment
- Openstack explanation (XXIII) -- other configurations, database initialization and service startup of neutron
- 1854. the most populous year
- js中的事件
- Device = depthai Device(““, False) TypeError: _init_(): incompatible constructor arguments.
猜你喜欢

MSF SMB based information collection

Sed explanation of shell script (SED command, sed -e, sed s/ new / old /...)

Identifier keyword literal data type base conversion character encoding variable data type explanation operator

Award winning survey streamnational sponsored 2022 Apache pulsar user questionnaire

Revisiting Self-Training for Few-Shot Learning of Language Model,EMNLP2021

Control statement if switch for while while break continue
![Error [detectionnetwork (1)][warning]network compiled for 6 shapes, maximum available 10, compiling for 5 S](/img/54/f42146ae649836fe7070ac90f2160e.png)
Error [detectionnetwork (1)][warning]network compiled for 6 shapes, maximum available 10, compiling for 5 S

ESP8266_通过MQTT协议连接阿里云

CVPR 2021: learning continuous image representation with local implicit image function

报错ModularNotFoundError: No module named ‘find_version’
随机推荐
[software] ten skills to maximize the value of ERP system
Exclusive interview - dialogue on open source Zhai Jia: excellent open source projects should be seen by more people. I am honored to participate in them
Runtimeerror: blobreader error:the version of imported blob doesn't match graph_ transformer
ES6新增特性--箭头函数
Detailed explanation of this and static
Opencv oak-d-w wide angle camera test
Pytorch installation for getting started with deep learning
CVPR 2021: learning continuous image representation with local implicit image function
Day45 storage engine data type integer floating point character type date type enumeration and set type constraints table to table relationships
js基础--Date对象
What are the types of garment ERP system in the market?
Console you don't know
Openstack explanation (22) -- neutron plug-in configuration
报错[error] input tesnor exceeds available data range [NeuralNetwork(3)] [error] Input tensor ‘0‘ (0)
Flask (VI) - template
Importance of implementation of clothing ERP in the project
Version mismatch between installed deeply lib and the required one by the script
Day 47 how to query a table
Identifier keyword literal data type base conversion character encoding variable data type explanation operator
1400. construct K palindrome strings