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)
}
添加回答
舉報