Cov lus cog tseg ua haujlwm li cas JavaScript?
Cov lus cog tseg ua haujlwm li cas JavaScript?

Video: Cov lus cog tseg ua haujlwm li cas JavaScript?

Video: Cov lus cog tseg ua haujlwm li cas JavaScript?
Video: qhia txog kev koj yuav coj cwj pwm hais lus li cas thiaj muaj phooj ywg kwv tij hwm koj 2024, Plaub Hlis Ntuj
Anonim

Ua Peb Tus Kheej JavaScript Promises

Cov cog lus constructor siv lub luag haujlwm (tus executor) uas yuav raug tua tam sim ntawd thiab dhau mus rau ob txoj haujlwm: daws, uas yuav tsum raug hu thaum lub cog lus raug daws (dhau ib qho txiaj ntsig), thiab tsis lees paub, thaum nws tsis lees paub (dhau qhov yuam kev).

Xav txog qhov no, cov lus cog tseg hauv JavaScript yog dab tsi?

JavaScript | Kev cog lus . Kev cog lus yog siv los tswj cov haujlwm asynchronous hauv JavaScript . Lawv yooj yim los tswj thaum cuam tshuam nrog ntau yam haujlwm asynchronous qhov twg callbacks tuaj yeem tsim kev hu rov qab ntuj raug txim ua rau tsis muaj cai tswj tau.

Tsis tas li ntawd, vim li cas peb thiaj xav tau cov lus cog tseg hauv JavaScript? Cov lus cog tseg cia ua yuam kev dhau los ntawm cov saw hlau thiab ua haujlwm hauv ib qho chaw uas tsis tas yuav tsum tau muab tso rau hauv cov txheej txheem ntawm kev tuav yuam kev. cog lus cov khoom siv los ua haujlwm asynchronous. Los ntawm kab thib 1 ntawm MDN cov ntaub ntawv: Cov cog lus khoom yog siv rau asynchronous xam.

cov lus cog tseg ua haujlwm li cas hauv qab lub hood?

Kev cog lus , hauv qab hood . Koj tab tom hla kev hu xov tooj rov qab uas txhais cov cwj pwm tshwj xeeb ntawm koj cog lus . A cog lus yog lub thawv uas muab API rau peb tswj thiab hloov pauv tus nqi, thiab nws qhov tshwj xeeb yog tias nws cia peb tswj hwm thiab hloov cov txiaj ntsig uas yeej tsis tau muaj.

Puas yog JavaScript cog lus asynchronous?

Kev cog lus muab lwm txoj hauv kev yooj yim rau kev ua, sau thiab tswj asynchronous kev ua haujlwm thaum piv rau cov txheej txheem hu rov qab raws li kev cai. Lawv kuj tso cai rau koj lis asynchronous yuam kev siv txoj hauv kev uas zoo ib yam li synchronous sim / ntes.

Pom zoo: