Dab tsi yog getter thiab setter hauv JavaScript?
Dab tsi yog getter thiab setter hauv JavaScript?

Video: Dab tsi yog getter thiab setter hauv JavaScript?

Video: Dab tsi yog getter thiab setter hauv JavaScript?
Video: Yog hmoov dab tsi - Gao Nou Kue ft. Mang Vang (Official Music Video) New song 2020 2024, Kaum ib hlis
Anonim

Ob lo lus tseem ceeb no txhais cov haujlwm nkag mus: a tau txais thiab a tus txheej txheem rau lub npe tag nrho. Thaum cov cuab yeej nkag mus, tus nqi rov qab los ntawm qhov tau txais yog siv. Thaum tus nqi raug teeb tsa, tus tus txheej txheem yog hu thiab dhau tus nqi uas tau teem tseg.

Kuj kom paub yog, kuv yuav tsum siv getters thiab setters hauv JavaScript?

Koj tsis tas yuav tsum tau siv getters thiab setters thaum tsim ib JavaScript khoom, tab sis lawv tuaj yeem pab tau ntau zaus. Feem ntau siv cov xwm txheej yog (1) kev ruaj ntseg nkag mus rau cov ntaub ntawv cov khoom thiab (2) ntxiv cov logic ntxiv rau cov khoom ua ntej tau txais lossis teeb tsa lawv cov txiaj ntsig.

setters thiab getters yog dab tsi? Hauv Java, getter thiab setter yog ob txoj hauv kev uas yog siv los kho thiab hloov kho tus nqi ntawm qhov sib txawv. Yog li ntawd, a tus txheej txheem yog ib txoj hauv kev uas hloov kho tus nqi ntawm qhov sib txawv. Thiab a tau txais yog ib txoj kev uas nyeem tus nqi ntawm qhov sib txawv. Getter thiab setter tseem hu ua accessor thiab mutator hauv Java.

Tsis tas li ntawd, dab tsi yog getter hauv JavaScript?

Tau txais muab ib txoj hauv kev los txhais cov cuab yeej ntawm ib yam khoom, tab sis lawv tsis suav cov cuab yeej tus nqi kom txog thaum nws nkag mus. A tau txais defers tus nqi ntawm kev xam tus nqi kom txog thaum tus nqi xav tau.

Dab tsi yog getters thiab setters thiab vim li cas lawv tseem ceeb?

Teb: Getters thiab setters yog cov txheej txheem siv los tshaj tawm lossis tau txais cov txiaj ntsig ntawm qhov sib txawv, feem ntau yog cov khoom ntiag tug. Lawv yog tseem ceeb vim nws tso cai rau qhov chaw nruab nrab uas muaj peev xwm tswj tau cov ntaub ntawv ua ntej tshaj tawm lossis xa rov qab rau tus tsim tawm.

Pom zoo: