javascript - 将 RxJS 与 filter(Boolean) 一起用于查询?

标签 javascript angular typescript rxjs rxjs6

我正在阅读一些代码片段:

search(query: string) {
  of(query).
  pipe(
    filter(Boolean), 
    debounceTime(300), 

filter(Boolean) 本质上和 filter(v=>!!v) 是一样的吗?

最佳答案

是的,它们是一样的。

   console.log(typeof Boolean); // prints function
   console.log(Boolean.prototype.constructor("truthy")); // prints true
   console.log(Boolean === Boolean.prototype.constructor); // prints true

Boolean 全局引用指向从第一个参数返回 bool 值的构造函数。

构造函数可用于创建一个boolean 包装器对象,但它与原始true 值不同。

    console.log(new Boolean("truthy")); // prints an object.
    console.log(new Boolean("truthy").valueOf() === true); // prints true
    console.log((new Boolean("truthy")) === true); // prints false
    console.log(Boolean("truthy") === true); // prints true

引用:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean

关于javascript - 将 RxJS 与 filter(Boolean) 一起用于查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53953015/

相关文章:

javascript - 如何在 Angular 10 项目中使用 chart.js 在条形图上显示数据标签?

css - 如何更改 ionic3 中模态的位置?

html - 我可以在移动浏览器上自动读取OTP吗?

javascript - 在 Controller 的 onInit 中读取 OData 上下文

Javascript - 动态转换js包括数组

angular - 如何使用 angular CLI 排除 lint 目录下的所有文件?

javascript - Angular 2 : Type 'Subscription' is not assignable to type

javascript - React 容器中在哪里初始化 Socket 对象?

javascript - 没有给定json值时如何显示警告框

Angular 2 - 存储全局变量(如身份验证 token )以便所有类都可以访问它们的最佳方法是什么?