Kibana6.x.x源码分析--JavaScript中 "!~" 这样的符号是啥意思?
2024-08-22 00:57:36
看到源码中有一段JS代码不太懂,如下:
里面这个 "!~" 符号看到后有点儿方啊O__O "…,毛线意思?
【查资料,解释如下】:
indexOf
returns -1 when an element cannot be found in an array. Therefore, the if
statement is checking if name
could not be found in names
. !~-1 ==> true
indeOf 数组方法在应用时,如果元素不存在于数组内则返回 -1 。因此,申明一个元素不在数组内的,就可以使用语法 !~-1 //true
The tilde (~
) operator (bitwise NOT) yields the inverted value (a.k.a. one’s complement) of a.
波浪线 ~ 操作符会按位取反
~-1 === 0
. Note that 0 == false
and !0 === true
.
注意到 0 == false 、!0 === true
indexOf
returns -1 when an element cannot be found in an array.
当元素不存在数组内时,indexOf 返回 -1
Therefore, we can use !~-1 === true
to find out if indexOf
could not find name
in names
(i.e. returned -1).
因此,元素不存在数组内的话,就可以使用 !~-1 === true 来进行判断
最新文章
- SSM集成(一):Mybatis3测试
- Oracle创建自增ID
- [笔记]linux下和windows下的 创建线程函数
- Memcache之telnet操作
- Delphi基本类型--枚举 子界 集合 数组
- 关于vue.js中class与style绑定的学习
- 关于display:flex
- 生成PHP数组文件
- jdk新特性
- Ural 1018 (树形DP+背包+优化)
- Qt---- 点击按钮调用另一个窗口Ui
- HDOJ(HDU) 2401 Baskets of Gold Coins(数列、)
- Linux 安装Nginx详细图解教程
- 淘宝PK京东:哥刷的不是广告,刷的是存在
- K:HashMap中hash函数的作用
- 【BZOJ1212】L语言(AC自动机)
- C# 反射及应用
- 物联网架构成长之路(22)-Docker练习之Etcd服务搭建
- Java 输入/输出——Java虚拟机读写其它进程的数据
- SP_OACreate提权经验