当前位置:网站首页>一些多参数函数的具体作用
一些多参数函数的具体作用
2022-07-28 11:10:00 【卷王出征】
经常能碰到一些js函数有多个参数,今天来整理一下,会持续更新的!!!
1. addEventListener()
我们知道点击或者其他事件触发时,对应的dom元素有三个阶段:捕获——目标——冒泡,第三个参数可以区分开是捕获阶段(由外向内)还是冒泡阶段(由内向外),同样我们改变下面这两个函数的位置,可以先让dom元素冒泡再捕获。
addEventListener('onclick',function(){
console.log('这是捕获阶段')
},true);
addEventListener('onclick',function(){
console.log('这是冒泡阶段')
},true)
2. sort
sort方法是js数组排序(改变原数组的7大方法之一)的方法,默认不传,数组内元素会按照unicode排序。如果,我们想让他按照由小到大的顺序排的话,可以传一个函数,如下:
[1,4,2,6,4,8,6].sort((a,b)=>a-b)
其实这是一个方法的简写,想了解的小伙伴可以去查一查。
3. splice、slice
这个两个方法,在数组中都有,剪切的效果。但是splice改变原数组,slice返回新数组。
splice(开始索引,共剪切几位)
slice(开始索引,结束索引(不包含这一位))
此外,slice还可以用于字符串的剪切。
4.setTimeout()、setInterval
setTimeout和setInterval第三个参数,一般用于,给内部的函数(第二个参数) 传参
function sum(x, y) {
console.log(x+y) //3
}
setTimeout(sum, 1000, 1, 2, 3);
如下其实是不对的,没有延迟效果:
function sum(x, y) {
console.log(x + y); //3
}
setTimeout(sum(1, 2), 1000);
边栏推荐
- 什么是WordPress
- Function of interface test
- 小水滴2.0网站导航网模板
- [pyGame practice] when the end of the world comes, how long can you live in a cruel survival game that really starts from scratch?
- In order to ensure the normal operation of fire-fighting equipment in large buildings, the power supply monitoring system of fire-fighting equipment plays a key role
- 一文看懂设备指纹如何防篡改、防劫持
- Google Earth Engine——使用geetool批量下载单景影像以Landsat 8 反演后的NDSI结果
- How to effectively implement a rapid and reasonable safety evacuation system in hospitals
- 万字详解 Google Play 上架应用标准包格式 AAB
- 完整版H5社交聊天平台源码[完整数据库+完整文档教程]
猜你喜欢

一文看懂设备指纹如何防篡改、防劫持

What is the process of switching c read / write files from user mode to kernel mode?

An example of the mandatory measures of Microsoft edge browser tracking prevention

Excel shortcut keys (letters + numbers) Encyclopedia

Cvpr2020 best paper: unsupervised learning of symmetric deformable 3D objects
![[geek challenge 2019] babysql-1 | SQL injection](/img/21/b5b4727178a585e610d743e92248f7.png)
[geek challenge 2019] babysql-1 | SQL injection

Techniques for visualizing large time series.

Solutions to the disappearance of Jupiter, spyder, Anaconda prompt and navigator shortcut keys

Ripro9.0 revised and upgraded version +wp two beautification packages + rare plug-ins
![Full version of H5 social chat platform source code [complete database + complete document tutorial]](/img/3f/03239c1b4d6906766348d545a4f234.png)
Full version of H5 social chat platform source code [complete database + complete document tutorial]
随机推荐
CVPR2021 行人重识别/Person Re-identification 论文+开源代码汇总
Leecode8 string conversion integer (ATOI)
Database advanced learning notes - system package
Update dev (development version) of the latest win11
LabVIEW AI visual Toolkit (non Ni vision) download and installation tutorial
Quickly deploy mqtt clusters on AWS using terraform
Embrace open source guidelines
【MySQL】Got an error reading communication packets
R language uses LM function to build regression model and regression model for transformed data (for example, it is necessary to build regression model for X and y, but they have no linear relationshi
Thinkphp5 behavior hook return result (data) example
Summary of common RSA related problems in CTF: basic RSA encryption and decryption
Open source huizhichuang future | 2022 open atom global open source summit openatom openeuler sub forum was successfully held
Cvpr2020 best paper: unsupervised learning of symmetric deformable 3D objects
Boutique scheme | Haitai Fangyuan full stack data security management scheme sets a "security lock" for data
A lock faster than read-write lock. Don't get to know it quickly
Are interviews all about memorizing answers?
[MySQL] MySQL error "error 2006 (HY000): MySQL server has gone away"
小水滴2.0网站导航网模板
Digital twin rail transit: "intelligent" monitoring to clear the pain points of urban operation
Database advanced learning notes - storage structure