5 回答
TA贡献1784条经验 获得超8个赞
f = url === this.last_product_url将结果分配url === this.last_product_url给 f。
f && productUrls.push(url) 如下:
if(f) productUrls.push(url)
TA贡献1946条经验 获得超4个赞
从语法上讲,这就是发生的事情:
f = url === this.last_product_url:
检查变量和分配给之间的url严格this.last_product_url相等f。
f && productUrls.push(url):
如果f是true,推url到productUrls。
这工作如下。该语句A && B被评估,但B仅检查是否A为真,因为如果A为假,A && B则永远不会为真。因此,如果A为真,则B检查:url 被推送。
TA贡献1871条经验 获得超8个赞
f = url === this.last_product_url f && productUrls.push(url)
这两行代码是表示以下逻辑的紧凑方式:
if(url === this.last_product_url){
productUrls.push(url);}TA贡献1796条经验 获得超4个赞
两条线在做
f = (url === this.last_product_url);
if (f) {
productUrls.push(url);
}
循环体可以通过编写来澄清
let f = !this.last_product_url;
for (const productLink of productLinks) {
const url = await productLink.getAttribute('href')
if (!f) {
f = (url === this.last_product_url);
}
if (f) {
productUrls.push(url);
}
}
但是这个奇怪f的标志真正做的是从productLinkswhere 之后获取所有 url url === this.last_product_url。所以整个事情可能应该写成
const allProductUrls = await Promise.all(productLinks.map(productLink =>
productlink.getAttribute('href');
));
const lastIndex = this.last_product_url
? allProductUrls.indexOf(this.last_product_url)
: 0;
if (lastIndex > -1) {
productUrls.push(...allProductUrls.slice(lastIndex));
}
TA贡献1864条经验 获得超6个赞
f = url === this.last_product_url相当于
if (url === this.last_product_url) {
f = true;
} else {
f = false;
}
和
f && productUrls.push(url)相当于
if (f) {
productUrls.push(url)
}
添加回答
举报
