0% found this document useful (0 votes)
38 views

Class Inheritance (Subclasses), Super Keyword, Constructors (Under The Hood)

Uploaded by

rounakbhowmick
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

Class Inheritance (Subclasses), Super Keyword, Constructors (Under The Hood)

Uploaded by

rounakbhowmick
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

(Page No.

Date

class inhetitonce (subclasse


A Classes which inheit functionatity fiom Ahothey
(lass also baue theis 0wn additionatpPrties og
methods too 01e_alled an subctossRs Og (lass inheitance.

in _othe1 wodsa Sublass extnds another clos5.

ronsteuctoe(usefname.emoil)
this. dse¬name =UseEname_
ths. endil =emaílj

ogin) 1 CLthis.USEIname_helto)
Onsolefog
etuenthis

l0gout(4 4this-useTName Good


(onsole-og4
etuen th

Class Admia_exhds

Usnone=AeWUses(tmgsio'hlo@múl.(om)
nst
fonst_sP1Tuo =ey_Usea("hetogood@gmail: (om)
onst r Tnee = Adnin('shqun,'shaun@gmail-(om )_
fon2ole.loqlUse Thiee)
(PagaNo.
Data T

gnait.1om"
Admin_fusunome : "shaun"tmail2"haun®
when_ye Cti
ie
and whm w_exkhd 4he_admin_
d n i R _qet folouing sesult
Parnauhangamaihlom"
USNameshadn"

-ppoto- Js4s_
Conate uctoE Class Adminh
V-pyoto
(Onsteucte class dseE
login _i loginc)
logaut f logout
-pöoto : Object
inhritance
hee haueUsed he_oLept of (luss
thot is vhy Pranple u-paw_y4t-4
TE Tt Tated admT ONd t adnin r0sS We hive
Gll nGtHhod5 Uses, Class hgve.
phch 0U5
HYe we have afed the admin cluss uhich exftnds
he V5e% class Ond. theefde e ge+ a Ptopeotes
Ond method5 nhI Tde ddmin tlass

And Now (On define extea methods dnd


20peaties in_adnin _cdassif _want to hat
Only adnins have
o sethis(onsides betog ex dmple
,
(Page No.

Date

class Use
(Ons teuctoE (UStENgMe;email){_
this-useename »Useename
this emaileemgil

loginc)
On sote-log tthis.useanamej loged in)
expioAato
class AdniA Axtknds Js6
CACAgtion deleteUsreuseUsEsE){ filtte((u) =7 _ 0
USe Es =
etuen d.UseEogme_fezuset-useEname

onst UseEOne =he Usee('mgsio "maeio@amúl.om')


onst see Thie=nego Admin"heltohetlo@gmail:(om)
letUseEs= UeEOne usee Thiee;
on sole-l0q/Use£S)
Usee. Thoee deleteUsee (UseeOne),
onsote-toq(usees) along
w t hh a t A o a i !

d n Joginmthod

(a) [UseeE,AdminJ
(0[Admin
any hav a teto
ahe_now we
wh emoit and toat mthed
onG,
hete,we hove doltted 'useeOne
i.magio wi# tnail nd Nhod
Page No.

Oat

(onztEu(De.
pothoue_a_
sf this admin_class does ui oo-_to
inside it then automaticaly t
(l0ss that xHndsHndsEm dnd hen
it wil tal tat (onsttuctoe

U5s u filtee {(u)


tuen u-USe£narme : VeE.USeENane_

wEitHh0s
ttke
h

WS1s =Usee filte(u=U.Us¢ENome s£: USeENome)_


Just we-hTVe sho2fiNd..

OUE code

So now _hove heeR_0 00105sHdmin"_


which_xtends the "gsee", it_inheaitsallof the
methodsOnd_opentils thtt (l0ss "UseE has
but hese hou OnlyAdmin"has the
"hsee Delet" method
Prd shen tty to gse hot Usei Delete method
in (lass ee we_uí_get_eEtoE._
i:e 0shoet Only admins_(an_ use th
"UsEDeleH" me thod.
(Page No.

Date

Nou what if closs Admin"te_ (las "Admn ho


shoutd e add sme extea piopeties gs we{_g5
metAodss0 Foe that We Aeed to have Admin class
onsteuctoe Ond also inheit the methodsond_piopeties
a f gnotho constéucto£_ in_pevUs exangle «UseE
hos its OuwN (0n>tuctodE
30to do this (onsidee neKt

NOw what if add additional_proppsties to nly lass


"Admin nd pe don't wont those pvopesties to be in
tass Usee"_ Only uant "Admin"_ to have h se
addikionalpopesties
o s0e Hhese_e_need to define 0u7_OWn ZonstEuctoE
inside the "Admn" cluss brause that 1s whe1e_propesties
atei defined inside a dl0ss
hen we_(all SupeE)hsidk a (0nsteuctoe Hen it
00s foe the _p0atnt class and It 0oks inide that_
(4 (0nstiuctot.
(Paga No.

ClassUseg
fonstfuctos (UsCgnome,maiU){
this.uiseengme = Uséenane
this. emate emaitj

logind this-useEnamej log9ed in");_


(unsole-tog
7etuen this_

Jogout(
(915ale.l0g$KKis-useEnamet logged out")_
etutn this

Class Adain exknds Us£ 1


0stEuctos (UseenOMe, PmaLtitte )
upet(Useerane ernaul) kpl4aatión on
this tite - titte
h
deietedsegLUseE) Au
USeEs= USeES-filtRE(U> UUseENgme ==Us{EURSNMME)j

onst sei0ne=Atw dses('heto"heto@gmail:com))_


Mst UsesTuo =new Usee('no,'nono@gmai-(om')
(Mst_UseihRe =new Admint'yes'yes( gmgil.om,' ol)
fonsole.log (Uses Tiee)
(Page No.
Date

vAdmin usernome : "yes"email: "ys@gml-lom",


Hte:" ola"
Pmail "yes@gmoik(om"
titte: "ota
Use1ngme: " yes"
oto:Usee

No heee onty cdass "Admin have piopetky (atted"titte"


Regulae"Jsee" "(j05s won't_
HEie class "Uses" has two psopesties and tuo methods
but lass "Adin'has nos its Own e_propt
Called He" because_whave Used theiE (0nst¬u(toE
Ond in Lon tutto£. We_hove_also ustdsupee()1so its
meaning 1s alng_with On_popity "HHAdmin" class
lso s fwo lopesties of dassseE_so_in tota
Closs "Admin" has thêee. psopestiko.
Also "Admin"_(lgss has dmettod (altd "delea0seg"
Clas's." segt has tyo hethodslogin) nd bgout
but no "deltteUsee" but in ctass nA donin"_Whave
access to loginc) ond logoutco fotu "Mmin"
tasshs hte_nethodstoo0.
Ord toyooFt dut to
Paga No.
Date

We
i d e

whenwitu not gsethis þelou) lne_

Supe E uStNme,emgi)
F We w het use this then we ill g
tollowinqtEOE.
Uncou ght Rtftemce E&£0E:Must (aIL Supet
on teuctoE In deeived ctdss befoge acoessinq
his 0tetuohing_fom deived_onste stuctog
Consteuctogs (undee the hood

Befoge 'class_was jntroducedwe woud wite


cade as feltoying
eldtt
a
funttion Useefusenome, emaúi) {
thsUses nante =Useanome exacHty thëJaME-
this emal= mcit
.

( l a s s W t A t

intyodyted -
class Usees
(onsteuctot(usesn ame, Pnt) t h es u M e A L t P U t

h1 SUsrSn ame =useingime


his email=emaul
isTtspon.2IÞ{e_

fontuetoe
HK ntu-Pites
fot settingupyhe
Page No.

Date

Nou what ifw_vant to add methods_using oldet way


fot thot(onsi de betou (ode Tupitor 3oitinditate
this Atst (t*s is
hat htontoris-a-
function Uses(usuoome,tmgit) {_ foAstiuAog-
this-usesnome=UPINOMe
ths-Pmail=email_
this.10gin-function()1
on sole-tog({this.useHnae_koggedin )_

0nst set One new Uses ('heto,"hauo@ynailluon)_


sE Ong loqinC)
we cando
this-
heto logged n because hi5
Hte aove Gdded s tance Ínstde
method 1atled "ognc) ConstettteE-

We(anadd funtions methods_ike_we_hgve_dane


Okove but hese is bettte way b add methods
OuE bjects not_ inside the_(onsteuto£
And hat_is whee Piototype (omes into "pichre

You might also like