Chav kawm hauv JavaScript yog dab tsi?
Chav kawm hauv JavaScript yog dab tsi?

Video: Chav kawm hauv JavaScript yog dab tsi?

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

Nyob rau hauv object-oriented programming, a chav kawm yog ib qho kev pab cuam-code-tus qauv rau kev tsim cov khoom, muab qhov tseem ceeb rau lub xeev (tus tswv cuab hloov pauv) thiab kev siv tus cwj pwm (cov tswv cuab kev ua haujlwm lossis cov txheej txheem).

Tsuas yog li ntawd, chav kawm hauv JS yog dab tsi?

Cov chav kawm Yog Function A chav kawm JavaScript yog hom kev ua haujlwm. Cov chav kawm tau tshaj tawm nrog cov chav kawm lo lus tseem ceeb. Cov cai tshaj tawm nrog kev ua haujlwm thiab chav kawm ob leeg rov ua haujlwm [Prototype]. Nrog prototypes, txhua txoj haujlwm tuaj yeem dhau los ua tus tsim qauv siv cov ntsiab lus tshiab.

Ib yam li ntawd, koj sau cov chav kawm li cas hauv JavaScript? Siv lo lus tseem ceeb chav kawm tsim ib chav kawm , thiab ib txwm ntxiv cov constructor() txoj kev. Cov txheej txheem constructor hu ua txhua lub sijhawm chav kawm khoom yog pib.

Tom qab ntawd, ib tus tuaj yeem nug, puas muaj chav kawm hauv JavaScript?

Nws yog ib qho tseem ceeb kom nco ntsoov tias tsis muaj cov chav kawm hauv JavaScript. Kev ua haujlwm tuaj yeem siv rau qee qhov simulate cov chav kawm, tab sis feem ntau JavaScript yog hom lus tsawg dua. Txhua yam yog ib qho khoom . Thiab thaum nws los txog qub txeeg qub teg, cov khoom qub txeeg qub teg los ntawm cov khoom, tsis yog cov chav kawm los ntawm cov chav kawm xws li hauv "chav kawm"-ical lus.

Kuv puas yuav tsum siv cov chav kawm hauv JavaScript?

Cov chav kawm ua cov qauv los tsim cov khoom tshiab. Qhov tseem ceeb tshaj plaws uas yuav tsum nco ntsoov: Cov chav kawm yog li qub JavaScript functions thiab ua tau yuav replicated kiag li tsis muaj siv tus chav kawm syntax. Nws yog tshwj xeeb syntactic qab zib ntxiv hauv ES6 kom nws yooj yim dua rau tshaj tawm thiab tau txais cov khoom siv.

Pom zoo: