当前位置:网站首页>一些多参数函数的具体作用
一些多参数函数的具体作用
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);
边栏推荐
- Full version of H5 social chat platform source code [complete database + complete document tutorial]
- 移动端人脸风格化技术的应用
- CVPR2020 best paper:对称可变形三维物体的无监督学习
- [general database integrated development environment] Shanghai daoning provides you with Aqua Data Studio downloads, tutorials, and trials
- Refresh your understanding of redis cluster
- [collection] Advanced Mathematics: Capriccio of stars
- I/O实操之对象流(序列化与反序列化)
- A natural choice
- Introduction to web security RADIUS protocol application
- PFP会是数字藏品的未来吗?
猜你喜欢

Byte side: how to realize reliable transmission with UDP?

Open source huizhichuang future | 2022 open atom global open source summit openatom openeuler sub forum was successfully held

PKG packaging node project

可视化大型时间序列的技巧。

「学习笔记」树状数组

Five Ali technical experts have been offered. How many interview questions can you answer

CVPR2020 best paper:对称可变形三维物体的无监督学习
![ASP. Net core 6 framework unveiling example demonstration [29]: building a file server](/img/90/40869d7c03f09010beb989af07e2f0.png)
ASP. Net core 6 framework unveiling example demonstration [29]: building a file server
![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]

ripro9.0修正升级版+WP两款美化包+稀有插件
随机推荐
Blackboard cleaning effect shows H5 source code + very romantic / BGM attached
R language - some metrics for unbalanced data sets
一文看懂设备指纹如何防篡改、防劫持
Excel shortcut keys (letters + numbers) Encyclopedia
Can dynamic partitions be configured when MySQL is offline synchronized to ODPs
什么是WordPress
Open source huizhichuang future | 2022 open atom global open source summit openatom openeuler sub forum was successfully held
LabVIEW AI visual Toolkit (non Ni vision) download and installation tutorial
B2 sub theme / blog b2child sub theme / open source code
Ten thousand words detailed Google play online application standard package format AAB
What is WordPress
什么是WordPress
AlexNet—论文分析及复现
Four advantages of verification code to ensure mailbox security
Design and implementation of SSM personal blog system
融云 IM & RTC 能力上新盘点
Design a system that supports millions of users
擦黑板特效表白H5源码+非常浪漫/附BGM
LabVIEW AI视觉工具包(非NI Vision)下载与安装教程
完整版H5社交聊天平台源码[完整数据库+完整文档教程]