SOURCE

function test() {
    return new Promise((res, rej) => {
        const r = Math.random();
        if (r > 0.5) {
            res(r)
        } else {
            rej(new Error('error'))
        }
    })
}

// test().then((res) => {
//     console.log(res)
// }).catch((e) => {
//     console.log(e, e.message)
// })
const p1 =test()
const p2 =test()
const p3 =test()
const ps = [p1, p2,p3]

// Promise.all(ps).then((r) => {
//     console.log(r)
// }).catch((e) => {
//     console.log(e, e.message)
// })
// Promise.allSettled(ps).then((r) => {
//     console.log(JSON.stringify(r), 'settle')
// }).catch((e) => {
//     console.log(e, e.message)
// })


Promise.allSettled2 = (arr) => {
    return new Promise(async (resolve, reject) => {
        const res = []
        arr.forEach( async item => {
            // item.then((r) => {
            //     res.push({status: 'fulfilled', value: r})
            // }).catch((e) => {
            //     res.push({status: 'reject'})
            // })
            const r = await item;
        })

    })
}


const a= {b:{c: {d: 1}}}
// func('a.b.c.d') 1

const func = (str) => {
    const arr = (str || '').split('.')
    console.log(arr, 'arr')
    const len = arr.length
    let obj = a;
    arr.forEach((item) => {
        console.log(item, obj)
        obj = obj[item]
    })
    console.log(obj)
    return obj;
}

func('b.c.d')
console 命令行工具 X clear

                    
>
console