国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

? ? ????? JS ???? JavaScript? ??? Promise ???

JavaScript? ??? Promise ???

Dec 28, 2024 pm 01:29 PM

Create your own Promise in JavaScript

???

JavaScript Promise? ??? ????? ??? ?????? ????? ???? ??.

??????? ??? Promise? ??? ???! Promise/A ??? ??? Promise? ??? ??? ????, ????, ????, ?? ??? ?? ? ?? ??? ???? ??? ?????.

?? ???? ???? ?? Promises/A ???? ?? ??? ?? ??? ??? ?????. ?? ?? ??? ??? ???? ?????. ??? ??? ??? ??? ????.

1. ??

1.1 'promise'? ? ??? ???? ??? ?? then ???? ?? ?? ?? ?????.

1.2 thenable'? then ???? ???? ?? ?? ?????.

1.3 '?'? ??? JavaScript ?(???? ??, Thenable ?? Promise ??)???.

1.4 '??'? throw ?? ???? ???? ????.

1.5 '??'? Promise? ??? ??? ???? ????.

2. ????

2.1 ?? ??

??? ??, ?? ?? ??? ? ?? ?? ? ???? ???.

2.1.1. ?? ?? ?? ??: ?

? ?? ?? ?? ??? ??? ? ????.

2.1.2. ???? ??: ?

? ?? ??? ???? ? ???.

? ?? ??? ?? ?????? ? ???.

2.1.3. ???? ??: ?

? ?? ??? ???? ? ???.

? ?? ? ?? ??? ??? ???.

2.2 then ???

Promise? ?? ?? ?? ??? ??? ????? ?? then ???? ???? ???.

Promise? then ???? ? ?? ??? ????:

promise.then(onFulfilled, onRejected);

2.2.1. onFulfilled ? onRejected? ?? ??? ?????: ?

? onFulfilled? ??? ??? ???? ???.

? onRejected? ??? ?? ?? ???? ???.

2.2.2. onFulfilled? ??? ??: ?

? Promise ?? ? ?? ??? ???? Promise? ??? ?? ???? ???.

? ??? ???? ??? ???? ? ???.

? ? ? ?? ???? ? ???.

2.2.3. onRejected? ??? ?? ?

? Promise? ??? ?? ???? ?? Promise? ??? ? ?? ??? ???? ???? ???.

? ??? ???? ?? ???? ? ???.

? ? ? ?? ???? ? ???.

2.2.4. ?? ???? ??? ??? ??? ??? ??? onFulfilled ?? onRejected? ???? ? ???. ?

2.2.5. onFulfilled ? onRejected? ??? ????? ???(?, ? ?? ??). ?

2.2.6. ?? ?? ??? Promise? ?? ?? ? ??? ? ????. ?

? ??? ???? ?? ?? onFulfilled ??? ?? ?? ???? ????? ???.

? ??? ???? ?? ?? ?? onRejected ??? ?? ?? ???? ????? ???.

2.2.7. ?? ?? ??? ???? ???. ?

promise.then(onFulfilled, onRejected);

? onFulfilled ?? onRejected? x ?? ???? ?? ?? ?? ?? [[Resolve]](promise2, x)? ?????. ?

? onFulfilled ?? onRejected?? ?? e? ???? promise2? e? ??? ????? ???. ?

? onFulfilled? ??? ??? promise1? ??? ?? promise2? promise1? ??? ??? ????? ???. ?

? onRejected? ??? ??? promise1? ??? ?? promise2? promise1? ?? ??? ????? ???. ?

??

JavaScript Promise? Promise? ??? ? ?? ???? ??? ??? ??? ?????.

promise2 = promise1.then(onFulfilled, onRejected);
new Promise(excecutor);

?? Promise/A ??? Promise? ??, ?? ?? ???? ??? ??? ????. ??? ???? ?? ????. ??? Promise ??? ?? ???? ??? JavaScript? ??? API? ????? ???. Promise ???? ? ?? ??? ??? ????.

const promise = new Promise((resolve, reject) => {
    // Runs some async or sync tasks
});

?? 2.1(?? ??)?? ??? ??, ?? ?? ??? ? ?? ?? ? ??? ??? ??? ???? ????. ?? ? ???? ?? ?? ????? ?????.

Promise? ????? ???? Promise? ?? ??? ?????? ? ???. ??? ??? ?? ?? Promise? ?? ???? ???? ???.

class YourPromise {
    constructor(executor) {
        this.state = 'pending';
        this.value = undefined;
        this.reason = undefined;

        const resolve = value => {
            if (this.state === 'pending') {
                this.state = 'fulfilled';
                this.value = value;
            }
        };

        const reject = reason => {
            if (this.state === 'pending') {
                this.state = 'rejected';
                this.reason = reason;
            }
        };

        try {
            executor(resolve, reject);  // The executor function being called immediately
        } catch (error) {
            reject(error);
        }
    }
}

????? ?? ??? ?? ???? ?? ?? ?? ??? ????? ????? ??? ??? ??? ????? ???.

const resolve = value => {
    if (this.state === 'pending') {
        this.state = 'fulfilled';
        this.value = value;
    }
};

const reject = reason => {
    if (this.state === 'pending') {
        this.state = 'rejected';
        this.reason = reason;
    }
};

??? ??? promise? ??????? ?? ????? ??? ??? ??? ?????.

this.state = 'pending';

YourPromise ???? ? ?? ??? ???? ???????.

Promise/A ??? ?? ?? ?? ??? then() ???? ???? ? ??? ???. ? ???? ???? Promise? ?? ?? ?? ??? ??? ???? ? ????. ??? ???????.

?? 2.2(then ???)??? Promise? ? ?? ??? ???? then() ???? ??? ??? ?????.

try {
    executor(resolve, reject);
} catch (error) {
    reject(error);
}

onFulfilled ? onRejected? ?? ??? ????? ??? ?? ????? ??, ??? ?? ??? ??? ??? ? ?? ??? ???? ???.

class YourPromise {
    constructor(executor) {
        // Implementation
    }

    then(onFulfilled, onRejected) {
        // Implementation
    }
}

?? ??? ????? ???? ?? ????? ? ??, ? ? ?? ???? ? ???. onFulfilled ? onRejected? ?? ?? ????? ??? ?? ?? ???? ???.

?? 2.2, 2.2.6, 2.2.7? ?? Promise?? then() ???? ??? ?? then() ???? ?? ? ??? ? ??? ??? ???? ??? ?? ? ? ????. ??:

promise.then(onFulfilled, onRejected);

???? ?? ?? ??? ???? ??? ??? ????. ??? ??? ???? Promise ??? ?????.

promise2 = promise1.then(onFulfilled, onRejected);

Executor ?? ??? ??? ???? onFulfilled ??? ???? ?? ??? ?????. ????? ??? ???? onRejected ??? ???? ?? ??? ?? ?????.

?? ??? Promise? ?? ?? ??? ?? onFulfilled ? onRejected ??? ??? ???? ??????. ??? ?? ??? ????? ???? ?????.

new Promise(excecutor);

?????. ??? then() ???? ???? Promise ???? ? ?? ?????.

const promise = new Promise((resolve, reject) => {
    // Runs some async or sync tasks
});

????? ??? ???? ?? ???? onFulfilledCallbacks ? onRejectedCallbacks?? ? ??? ?????. ??? ???? Promise? ?? ?? ?? then() ??? ?? ???? ???? Promise? ????? ??? ? ?????.

Promise ???? ???? ???.

class YourPromise {
    constructor(executor) {
        this.state = 'pending';
        this.value = undefined;
        this.reason = undefined;

        const resolve = value => {
            if (this.state === 'pending') {
                this.state = 'fulfilled';
                this.value = value;
            }
        };

        const reject = reason => {
            if (this.state === 'pending') {
                this.state = 'rejected';
                this.reason = reason;
            }
        };

        try {
            executor(resolve, reject);  // The executor function being called immediately
        } catch (error) {
            reject(error);
        }
    }
}

??? ?? ????? ???.

const resolve = value => {
    if (this.state === 'pending') {
        this.state = 'fulfilled';
        this.value = value;
    }
};

const reject = reason => {
    if (this.state === 'pending') {
        this.state = 'rejected';
        this.reason = reason;
    }
};

??, ?? ???? ????:

this.state = 'pending';

??? ?? ? ????:

try {
    executor(resolve, reject);
} catch (error) {
    reject(error);
}

??:

class YourPromise {
    constructor(executor) {
        // Implementation
    }

    then(onFulfilled, onRejected) {
        // Implementation
    }
}

??? ??? then()? ??? ? YourPromise ????? ?? ????? ??? ?? then() ???? ??? ???? ??? ????. ?? ?? ??? ?? ?? ?? ?? then() ???? ?? ??? ?? ???? ?? ???? ???? ???? ????. ??? ?? ?? ?? ??? ?????. ?? ??????:

? ??? '?? ??'??? ??? ?? ?????.

? promise.then()? ???? ??? ?? ??????? onFulfilled ??? ?? ???? ?? ???? ???? ?? ?? ?????.

??? ?? 2.2.4? ?????. ? ??? Promise? ?? ????? ??? ???? then() ??(onFulfilled ?? onRejected)? ?????? ????? ?????. ?, ?? ?? ??? ??? ???? ??? ??(?: ??? ?? ?? ???? ?? ???)? ??? ??? ??? ????? ? ???.

? ??? ? ??????

? ??? Promise/A ???? ?? ??? ?? ? ?????. ??? ???? ?????.

? Promise? ?? ?????? ?? then() ??? ??? ??? ?? ??? ???? ????.

? ? ??? setTimeout ?? process.nextTick? ?? JavaScript? ?? ??? API ??? ?????.

??? ?? ??? ? ????

?? setTimeout ?? setImmediate? ?? ??? ?? ?????? queueMicrotask ?? process.nextTick? ?? ???? ?? ????? ???? ??? ? ????. ???? ???? ??? ?? ?? ?? ??? ????? ??? ?? JavaScript ?? ????? ??? ?? ???? ?????.

? ??? ????? ??? ?? ????? ??? ???? ?? ??(onFulfilled ?? onRejected)? queueMicrotask? ???? ?????? ????? ?? ???. ??? ??? ??? ????.

promise.then(onFulfilled, onRejected);

?? ?? ??? ??? ?? ?????. ??? ?? ??? ?????.

promise2 = promise1.then(onFulfilled, onRejected);

?????.

?? then()? ??? ??? ???? ?? ???? ?? ????? ???? ??? ??? ?????? ???? ???? ???. JavaScript? ???? ??? ??? ????? ? ??? ??? ???? ?? ??????.

??? ?????? ? ????? ?? Promises/A ??? ??? ????? ? ?? ???? ?? ??? ??? ??? ? ? ????.

???? ????? ???? ????? ????! ??? ??????.

???:
LinkedIn, Medium, Github

? ??? JavaScript? ??? Promise ???? ?? ?????. ??? ??? PHP ??? ????? ?? ?? ??? ?????!

? ????? ??
? ?? ??? ????? ???? ??? ??????, ???? ?????? ????. ? ???? ?? ???? ?? ??? ?? ????. ???? ??? ???? ???? ??? ?? admin@php.cn?? ?????.

? AI ??

Undresser.AI Undress

Undresser.AI Undress

???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover

AI Clothes Remover

???? ?? ???? ??? AI ?????.

Video Face Swap

Video Face Swap

??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

???

?? ??

?? : ????? ????? ??
4 ? ? ? By DDD
?? ?? ??
3 ? ? ? By Jack chen
???

??? ??

???++7.3.1

???++7.3.1

???? ?? ?? ?? ???

SublimeText3 ??? ??

SublimeText3 ??? ??

??? ??, ???? ?? ????.

???? 13.0.1 ???

???? 13.0.1 ???

??? PHP ?? ?? ??

???? CS6

???? CS6

??? ? ?? ??

SublimeText3 Mac ??

SublimeText3 Mac ??

? ??? ?? ?? ?????(SublimeText3)

???

??? ??

?? ????
1787
16
Cakephp ????
1730
56
??? ????
1582
29
PHP ????
1450
31
???
Java vs. JavaScript : ??? ????? Java vs. JavaScript : ??? ????? Jun 20, 2025 am 12:27 AM

Java ? JavaScript? ?? ?? ????? ??? ?? ?? ?? ???? ????? ?????. Java? ??? ? ??? ?????? ??? ???? JavaScript? ?? ? ??? ??? ?????.

JS? ??? ???? ???? ??? JS? ??? ???? ???? ??? Jul 01, 2025 am 01:27 AM

JavaScript?? ??? ??? ?? ? ? ?? ??? ???????. 1. ?? ??? ??? ???? ?? ??? ????. ISO ?? ???? ???? ???? ???? ?? ????. 2. ?? ??? ?? ???? ??? ?? ???? ??? ? ??? ? ?? 0?? ????? ?? ??????. 3. ?? ?? ???? ???? ???? ?? ?????? ??? ? ????. 4. Luxon? ?? ???? ???? ?????? ???? ?? ????. ??? ?? ???? ????? ???? ??? ????? ?? ? ????.

? ? ???  ??? ?? ???? ??? ?????? ? ? ??? ??? ?? ???? ??? ?????? Jul 02, 2025 am 01:22 AM

TAGGSATTHEBOTTOMOFABLOGPOSTORWEBPAGESERVESPRACTICALPURSEO, USEREXPERIENCE, andDESIGN.1.ITHELPSWITHEOBYOWNSESPORENGENSTOESTOCESKESKERKESKERKERKERDER-RELEVANTTAGSWITHOUTHINGTEMAINCONTENT.2.ITIMPROVESEREXPERKEEPINGTOPONTEFOCUSOFOFOFOCUSOFOFOFOCUCUSONTHEATECLL

JavaScript vs. Java : ?????? ??? ? ?? JavaScript vs. Java : ?????? ??? ? ?? Jun 20, 2025 am 12:21 AM

JavaScriptIspreferredforwebDevelopment, whithjavaisbetterforlarge-scalebackendsystemsandandandoidapps.1) javascriptexcelsincreatinginteractivewebexperiences withitsdynatureanddommanipulation.2) javaoffersstrongtypingandobject-Orientededededededededededededededededdec

DOM?? ??? ?? ? ? ??? ?????? DOM?? ??? ?? ? ? ??? ?????? Jul 02, 2025 am 01:19 AM

??? ?? ? ??? DOM?? ??? ??? ? ?????. ??? ?? ????? ?? ??????, ??? ?? ???? ?? ????????. 1. ??? ??? addeventListener? usecapture ?? ??? true? ???? ?????. 2. ??? ??? ?? ???? usecapture? ???? ????? ?????. 3. ??? ??? ??? ??? ???? ? ??? ? ????. 4. ??? ?? ?? ?? ??? ?? ??? ??????? ??? ???? ?????. 5. ??? ?? ?? ?? ??? ?? ???? ?? ???? ? ??? ? ????. ? ? ??? ???? ???? JavaScript? ??? ??? ??? ????? ???? ???? ??? ??????.

JavaScript : ???? ????? ??? ?? ?? JavaScript : ???? ????? ??? ?? ?? Jun 20, 2025 am 12:46 AM

javascriptassevenfundamentalDatatatypes : ??, ???, ??, unull, ??, ? symbol.1) ?? seAdouble-precisionformat, ??? forwidevaluerangesbutbecautiouswithfatingfointarithmetic.2) stringsareimmutable, useefficientconcatenationmethendsf

JavaScript ?? ????? ???? ??? ??? ?? ? ????? JavaScript ?? ????? ???? ??? ??? ?? ? ????? Jun 26, 2025 am 12:54 AM

JavaScript ?? ????? ??????? ??? ?? ??? ??? ????? ?? ??? ????. ????? ??? ?????. 1. ?? ?? (CodesPlitting) ??, ?? ??? React.lazy ()? ?? ?? ?? ?? ??? ????? ??? ???? ? ?? ????? ??? ?? ??? ???????. 2. ???? ?? ?? (???)? ????, ES6 ?? ????? ???? "Dead Code"? ???? ?? ? ????? ?? ??? ??? ? ???????. 3. ?? ??? ???? ???? GZIP/BROTLI ? TERSER? JS? ???? ??? ????? ???? ?? ???? ??? ? ? ??????. 4. ??? ???? ???? day.js ? fetch? ?? ?? ?????? ??????.

JavaScript ??? ???? JS ??? ? : ES ?? ? CommonJS JavaScript ??? ???? JS ??? ? : ES ?? ? CommonJS Jul 02, 2025 am 01:28 AM

ES ??? CommonJS? ?? ???? ?? ?? ? ?? ???????. 1. Commonjs? ????????? Node.js ?? ? ??? ?????. 2.ES ??? ???????? ????? ?? ???? ??? ?????. 3. ??, ES ??? ?? ??/????? ???? ??? ??? ?????? CommonJS? Quiew/Module.exports? ???? ???? ???? ?? ? ? ????. 4. Commonjs? Express? ?? ???? Node.js ? ?????? ?? ???? ?? ???? ?? ES ??? ?? ??? ?? ??? ?? ? Node.jsv14? ?????. 5. ?? ? ? ??? ?? ??? ??? ? ????.

See all articles