Longyang
Longyang
  • 发布:2015-07-09 14:00
  • 更新:2015-12-18 11:40
  • 阅读:3191

~id.indexOf()前面的波浪号啥意思?

分类:MUI

比如这段代码:
~id.indexOf('offcanvas-with-right') ? "close" : "none";

2015-07-09 14:00 负责人:无 分享
已邀请:
Seven_Tao

Seven_Tao

~id.indexOf('offcanvas-with-right')
等同于
id.indexOf('offcanvas-with-right') > -1

波浪号可以做运算
~N == -(N+1)
~-1 = -(-1+1) = 0
~1 = -(1+1) = -2

也可以转义
~~'123' == 123
~~'-123' == -123
~~true == 1
~~false == 0

该问题目前已经被锁定, 无法添加新回复