Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #26472

Re: Why use prototype in this example

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail
From "Christoph M. Becker" <cmbecker69@arcor.de>
Newsgroups comp.lang.javascript
Subject Re: Why use prototype in this example
Date Tue, 06 Jan 2015 23:53:44 +0100
Organization solani.org
Lines 22
Message-ID <m8hp1m$oqg$1@solani.org> (permalink)
References <m8hnjv$d29$1@dont-email.me>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 7bit
X-Trace solani.org 1420584822 25424 eJwNx9sBADEEBMCWxGNRDiH9l3A3f2OCg+sKg9qzlweIVqLJ+r+8Eq/TSFwmpre2rzcP14C3PhnEEcE= (6 Jan 2015 22:53:42 GMT)
X-Complaints-To abuse@news.solani.org
NNTP-Posting-Date Tue, 6 Jan 2015 22:53:42 +0000 (UTC)
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0
X-User-ID eJwFwQcBwDAMAzBKcz6dnJk/hEqugdi08DCncxLTWikjtUew96dW0yGDE7TsVIV/pStnDy+1EX4=
In-Reply-To <m8hnjv$d29$1@dont-email.me>
Cancel-Lock sha1:AZX8IFqZdj6/aJqXzhZwRXomF9k=
X-NNTP-Posting-Host eJwFwQkRwEAIBDBLMLcsIIfy+JfQxB6V7aARdnZp8ZAHIUtjcvWqaxbX7m5v5VOJA2ImOf0DF2wRSg==
Xref csiph.com comp.lang.javascript:26472

Show key headers only | View raw


Tony Johansson wrote:

> Here I have two examples. The difference between these is that in
> example 1 I create sayHello as a prototype while in
> exemple 2 I add sayHello as a function in the class Person
> 
> I mean in both example 1 and 2 I create an instance of Person.
> I can't see any point to use a prototype compared to add methods to the
> class?

Thomas 'Pointed Ears' Lahn already gave a good answer in
<news:1590597.KOVAYohEvS@PointedEars.de>:

| Inherited methods can be reused.  In this example, one advantage is
| that only one Function instance is created, which saves memory as
| compared to the instance method approach.  It also saves runtime
| because the creation of that object only happens once.  (There are
| also disadvantages.)

-- 
Christoph M. Becker

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Why use prototype in this example "Tony Johansson" <johansson.andersson@telia.com> - 2015-01-06 23:29 +0100
  Re: Why use prototype in this example "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-01-06 23:53 +0100
  Re: Why use prototype in this example Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-01-07 04:25 +0100

csiph-web