当前位置:网站首页>一些多参数函数的具体作用
一些多参数函数的具体作用
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);
边栏推荐
- WPF layout controls are scaled up and down with the window, which is suitable for multi-resolution full screen filling applications
- R language ggplot2 visualization: ggdensity function of ggpubr package visualizes density graph and uses stat_ overlay_ normal_ Density function superimposes positive distribution curve, custom config
- Two point, three point, 01 point plan [bullet I]
- 一种比读写锁更快的锁,还不赶紧认识一下
- 可视化大型时间序列的技巧。
- Three methods of using unity mouse to drive objects
- mysql(8.0.16版)命令及说明
- Cvpr2020 best paper: unsupervised learning of symmetric deformable 3D objects
- I/O实操之对象流(序列化与反序列化)
- Learning notes tree array
猜你喜欢

Are interviews all about memorizing answers?

接口测试的作用

保障邮箱安全,验证码四个优势

zotero文献管理器及其使用姿势(不定时更新)

A lock faster than read-write lock. Don't get to know it quickly

拥抱开源指南

What functions does MySQL have? Don't look everywhere. Just look at this.
![[pyGame practice] when the end of the world comes, how long can you live in a cruel survival game that really starts from scratch?](/img/2b/1eb02249ab9ad0b4e1bfeeee87418c.png)
[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
随机推荐
Five Ali technical experts have been offered. How many interview questions can you answer
Ten thousand words detailed Google play online application standard package format AAB
【一知半解】零值拷贝
R language uses LM function to build regression model with interactive items, and uses: sign (colon) to represent the interaction of variables (colon is pure multiplication, excluding the constituent
Cvpr2020 best paper: unsupervised learning of symmetric deformable 3D objects
服务器在线测速系统源码
MySQL离线同步到odps的时候 可以配置动态分区吗
I want to ask you guys, if there is a master-slave switch when CDC collects mysql, is there any solution
[collection] Advanced Mathematics: Capriccio of stars
哪位大神帮看下 oracle number类型解析 怎么搞 Struct{scale=15,val
go status. Go status code definition
Design and implementation of SSM personal blog system
Object to object mapping -automapper
How to effectively implement a rapid and reasonable safety evacuation system in hospitals
Today's sleep quality record 74 points
Introduction to the usage of SAP ui5 image display control avatar trial version
Can dynamic partitions be configured when MySQL is offline synchronized to ODPs
一种比读写锁更快的锁,还不赶紧认识一下
Excel shortcut keys (letters + numbers) Encyclopedia
b2子主题/博客b2child子主题/开源源码