Video: Cov lus cog tseg ua haujlwm li cas hauv JavaScript?
2024 Tus sau: Lynn Donovan | [email protected]. Kawg hloov kho: 2023-12-15 23:47
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 Kev cog lus yog daws (dhau qhov tshwm sim), thiab tsis lees paub, thaum nws yog tsis lees paub (dhau qhov yuam kev).
Tom qab ntawd, dab tsi yog kev cog lus hauv JavaScript?
A cog lus yog ib yam khoom uas yuav tsim tau ib tug nqi ib lub sij hawm nyob rau hauv lub neej yav tom ntej: txawm ib tug daws teeb meem, los yog ib tug yog vim li cas nws tsis tau daws (xws li, ib tug network yuam kev tshwm sim). A cog lus tej zaum yuav nyob rau hauv ib qho ntawm 3 lub xeev: ua tiav, tsis lees paub, lossis tseem tos.
Tsis tas li ntawd, vim li cas peb thiaj siv cov lus cog tseg hauv JavaScript? Cov lus cog tseg yog siv los tswj cov haujlwm asynchronous hauv JavaScript . Lawv yog yooj yim los tswj thaum cuam tshuam nrog ntau yam haujlwm asynchronous qhov twg callbacks tuaj yeem tsim callback ntuj raug txim ua rau tsis muaj cai tswj tau. Cov lus cog tseg yog qhov kev xaiv zoo tshaj plaws rau kev tuav cov haujlwm asynchronous hauv qhov yooj yim tshaj plaws.
Tsuas yog li ntawd, cov lus cog tseg ua haujlwm li cas hauv qab lub hood?
Cov cog lus yog instantiated nrog cov nqe lus ntawm ib tug muaj nuj nqi uas nws invokes thaum lub sij hawm nws tsim, los ntawm uas nws encloses internal kev daws teeb meem thiab tsis kam ua haujlwm. Cov Kev cog lus ua haujlwm los ntawm ib yam dab tsi ntawm kev sib tw ntawm kev daws / tsis lees paub thiab tom qab ntawd.
Cov lus cog tseg ua haujlwm li cas?
TLDR: cog lus . tag nrho yog ib txoj kev Javascript uas yuav siv sij hawm ib tug iterable (xws li Array) ntawm cog lus raws li kev sib cav thiab rov qab ib leeg cog lus thaum tag nrho tus cog lus nyob rau hauv qhov kev sib cav iterable tau raug daws (los yog thaum nws sib cav tsis muaj cog lus ).
Pom zoo:
Cov lus cog tseg hauv cov ntawv sau yog dab tsi?
Cov lus cog tseg yog ib yam khoom TypeScript uas yog siv los sau cov kev pabcuam asynchronous. Kev cog lus ib txwm yog qhov kev xaiv zoo dua thaum nws los tswj ntau yam haujlwm asynchronous, kev ua yuam kev thiab kev nyeem cov lej zoo dua
Cov lus cog tseg hauv AngularJS yog dab tsi?
Kev cog lus yog ib yam khoom uas rov qab los ntawm Deferred object. Koj tuaj yeem sau npe sib txawv callbacks rau cov xwm txheej sib txawv daws(), tsis lees paub(), lossis ceeb toom() thiab nws yuav ua tiav thaum lub async ua tiav. Deferred API: Ib qho piv txwv tshiab ntawm defer yog tsim los ntawm kev hu $q
Puas muaj ib txoj hauv kev pov tseg qhov kev kuaj xyuas los ntawm txoj kev uas tsis muaj cov lus pov tseg?
9 Teb. Koj tuaj yeem pov cov kev txwv tsis raug txheeb xyuas yam tsis tas yuav tshaj tawm lawv yog tias koj xav tau tiag tiag. Unchecked kev zam txuas ntxiv RuntimeException. Throwables uas txuas ntxiv yuam kev tseem tsis tau txheeb xyuas, tab sis tsuas yog yuav tsum tau siv rau cov teeb meem loj tiag tiag (xws li invalid bytecode)
Dab tsi yog cov lus cog tseg hauv AngularJS?
Kev cog lus yog ib yam khoom uas rov qab los ntawm Deferred object. Koj tuaj yeem sau npe sib txawv callbacks rau cov xwm txheej sib txawv daws(), tsis lees paub(), lossis ceeb toom() thiab nws yuav ua tiav thaum lub async ua tiav. Deferred API: Ib qho piv txwv tshiab ntawm defer yog tsim los ntawm kev hu $q
Cov lus cog tseg ua haujlwm li cas JavaScript?
Ua Peb Tus Kheej JavaScript Promises Cov Lus Cog Tseg yuav siv lub luag haujlwm (tus neeg ua haujlwm) uas yuav tsum tau ua tam sim ntawd thiab dhau los ntawm ob txoj haujlwm: daws, uas yuav tsum raug hu thaum Cov Lus Cog Tseg raug daws (dhau qhov tshwm sim), thiab tsis lees paub, thaum nws tsis lees paub. (dhau qhov yuam kev)