Value through

Value penetration refers to the fact that when the arguments of a chain call are not functions, value penetration occurs and the non-function values passed in are ignored instead of the previous function arguments.

Promise.resolve(1)
    .then(2)
    .then(Promise.resolve(3))
    .then(console.log)
Copy the code



The fulfilled state of 2 or promise will occur.

Promise.resolve(1)
    .then(() = > { return 2 })
    .then(() = > { return 3 })
    .then(console.log)
Copy the code

Promise.resolve(1)
    .then(function () {
        return 2
    })
    .then(() = > { Promise.resolve(3) })
    .then(console.log)
Copy the code



Only the function passed in is passed to the next chain call.

Abnormal penetration

Promise.reject(1)
    .then(res= > {
        console.log(res);
    })
    .then(res= > { console.log(res) },
        rej= > {
            console.log(`rej****${rej}`);
        })
    .catch(err= > {
        console.log(`err****${err}`);
    })
Copy the code



When a second function is passed in then, no error is caught.

Promise.reject(1)
    .then(res= > {
        console.log(res);
    })
    .then(res= > { console.log(res) },
        rej= > {
            console.log(`rej****${rej}`);
        })
    .then(res= > {
        console.log(`res****${res}`);
    }, rej= > {
        console.log(`rej****${rej}`);
    })
    .catch(err= > {
        console.log(`err${err}`);
    })
Copy the code



Errors caught by THEN are also passed to the status of success of the next chain call, albeit undefined.


Record the record!