/    Sign up×
Community /Pin to ProfileBookmark

JS OOP using .prototype

I’m converting some of my bad code (we learn a little more every day) and trying to use propper JS OOP tech. I’ve been Googling a lot and reading everything I can find on using “.prototype” to manage JS object inheritance. I believe I have pretty good understanding at this point but one thing is still puzzling me. I read somewhere (one of the fifty sites I’ve been to) that adding public methods to an object via .prototype -does not- add the method (the method code) to every instance of the object. Therefore it is much more memory efficient. Is this true? If so, how can that actually work? How would this public method reference the individual object instances? Does this make sense?

Thanks for any tips 🙂

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@CharlesAug 07.2006 — When you call the method of some Object the intrepeter starts looking for it. First it looks for an instance, a methid that belongs only to that Object. Then it looks for a class method with that name and on up the chain.
Copy linkTweet thisAlerts:
@locoHostauthorAug 08.2006 — That makes sense. Thanks Charles :-)
×

Success!

Help @locoHost spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...