看到源码中有一段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 来进行判断

参考资料:https://stackoverflow.com/questions/28423512/whats-the-mean-in-javascript?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa

最新文章

  1. SSM集成(一):Mybatis3测试
  2. Oracle创建自增ID
  3. [笔记]linux下和windows下的 创建线程函数
  4. Memcache之telnet操作
  5. Delphi基本类型--枚举 子界 集合 数组
  6. 关于vue.js中class与style绑定的学习
  7. 关于display:flex
  8. 生成PHP数组文件
  9. jdk新特性
  10. Ural 1018 (树形DP+背包+优化)
  11. Qt---- 点击按钮调用另一个窗口Ui
  12. HDOJ(HDU) 2401 Baskets of Gold Coins(数列、)
  13. Linux 安装Nginx详细图解教程
  14. 淘宝PK京东:哥刷的不是广告,刷的是存在
  15. K:HashMap中hash函数的作用
  16. 【BZOJ1212】L语言(AC自动机)
  17. C# 反射及应用
  18. 物联网架构成长之路(22)-Docker练习之Etcd服务搭建
  19. Java 输入/输出——Java虚拟机读写其它进程的数据
  20. SP_OACreate提权经验

热门文章

  1. 724. Find Pivot Index 找到中轴下标
  2. opennebula模板对照比较
  3. Linux内核的特征
  4. ubuntu 安装两个版本的Anaconda
  5. Win10 DHCP和Static IP 切换
  6. 什么是Condition Number(条件数)?
  7. Spring MVC Hibernate MySQL Integration(集成) CRUD Example Tutorial【摘】
  8. MongoDB整理笔记の导入导出
  9. 十五、Node.js-fs模块(中)
  10. Setter