第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為什么 ind = index1() 的值不是 || 索引2();其中 index1()

為什么 ind = index1() 的值不是 || 索引2();其中 index1()

慕斯709654 2021-10-14 14:31:29
我有一個函數(shù) concat() ,它從某個開始到某個結束接受生成器函數(shù),并通過組合兩個生成器來充當另一個生成器。例如,如果第一個生成器函數(shù)生成一個從 0 到 2 的數(shù)字,第二個生成器生成一個從 0 到 1 的數(shù)字,則 concat() 生成 (0, 1, 2, 0, 1) 以供以后未定義的調用使用。實現(xiàn) concat() 后,在測試時,它返回 (0, 1, 2, 1) 以供以后未定義的調用使用。它跳過第二個生成器函數(shù)的第一個生成值。我已經(jīng)改變了我實施的方式并且它有效,但我不明白為什么它不適用于另一個。我試圖打印返回的立即結果,我發(fā)現(xiàn) 0 被跳過,因為第二個生成器和第一個生成器在放入 OR 操作時返回給 undefined 為第二個生成器的第一個值,正如我之前放置的 console.log 所指出的回來。我不知道為什么會這樣。多行注釋代碼按預期工作。兩者有什么不同?const from = (start) => {  return () => {    const next = start;    start += 1;    return next;  };};const to = (fromIndex, end) => {  return () => {    const at = fromIndex();    if (at < end) {      return at;    }    return undefined;  };};const fromTo = (start, end) => {  return to(from(start), end);};const concat = (index1, index2) => {  return () => {    let ind = index1() || index2();    // console.log(ind);    return ind;    /*                // THIS WORKS AS EXPECTED:           ind = index1();          if (ind !== undefined) {            return ind;          }          ind = index2();          if (ind !== undefined) {            return ind;          }          */  };};const con = concat(fromTo(0, 3), fromTo(0, 2));console.log('con(): ', con()); // 0console.log('con(): ', con()); // 1console.log('con(): ', con()); // 2console.log('con(): ', con()); // 1 but expecting 0console.log('con(): ', con()); // undefined but expecting 1我希望在控制臺中打印如下:        con(): 0        con(): 1        con(): 2        con(): 1 // but expecting 0        con(): undefined // but expecting 1
查看完整描述

1 回答

?
明月笑刀無情

TA貢獻1828條經(jīng)驗 獲得超4個贊

這是因為你有一個真實的檢查


當您致電index1()Return 時0。你有一個或。這里的問題是 or 說“0不真實”所以移到index2()


所以你不能只是做那個簡單的檢查,因此你的其他版本為什么有效。你能得到的最接近的東西是這樣的。


const concat = (index1, index2) => {

  return () => {

    const ind = index1()

    return ind !== undefined ? ind : index2()

  }

}


查看完整回答
反對 回復 2021-10-14
  • 1 回答
  • 0 關注
  • 258 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號