由于对任一数值 x 进行按位非操作的结果为 -(x + 1)。例如,5 结果为 -6,(-1) 结果为 0。
这就可以应用到用 .indexOf 来实现 lodash.contains 的功能:
if (text.indexOf('str') !== -1) {}
//=>
if (!~text.indexOf('str')) {}
例子:
参考:
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too