我正在阅读一些代码片段:
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/