gpt4 book ai didi

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

转载 作者:数据小太阳 更新时间:2023-10-29 05:56:36 24 4
gpt4 key购买 nike

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

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com