Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #17953
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | JJ <jaejunks@nah.meh> |
| Newsgroups | comp.lang.javascript |
| Subject | Re: Does copying the prototype reference from another constructor function maintain the prototype chain? |
| Date | Sat, 5 Jan 2013 10:57:02 +0000 (UTC) |
| Organization | A noiseless patient Spider |
| Lines | 57 |
| Message-ID | <XnsA13FB75B242F1jj@0.0.0.55> (permalink) |
| References | <kc8jjg$k07$1@speranza.aioe.org> |
| Injection-Date | Sat, 5 Jan 2013 10:57:02 +0000 (UTC) |
| Injection-Info | mx04.eternal-september.org; posting-host="8e9f622bcca1dbb9ccb65df5db97a1dc"; logging-data="27941"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19vwVhgYCTwIyTwPDQON2ikpQ13cHIKX3k=" |
| User-Agent | Xnews/5.04.25 |
| X-Face | \*\`0(1j~VfYC>ebz[&O.]=,Nm\oRM{of,liRO#7Eqi4|!]!(Gs=Akgh{J)605>C9Air?pad{sSZ09u+A7f<^paR"/NH_#<mE1S"hde\c6PZLUB[t/s5-+Iu5DSc?P0+4%,Hl |
| Cancel-Lock | sha1:VFR2c/gK7CiGTJtme9CQzxwbR1E= |
| Xref | csiph.com comp.lang.javascript:17953 |
Show key headers only | View raw
GGolf <invalid@invalid.com> wrote:
> I've been a Javascript dabbler for a few years, and have just embarked
> on learning more advanced stuff.
>
> I have the following question in a tutorial by John Resig:
>
> At http://ejohn.org/apps/learn/#76, Resig mentions that only the
> following maintains the prototype chain:
>
> Ninja.prototype = new Person();
>
> However, I notice that even the following statement makes all the test
> statements pass:
>
> Ninja.prototype = Person.prototype;
>
> Does it mean that using "Person.prototype" can actually be used instead
> of "new Person()"?
Yes.
"Ninja.prototype = Person.prototype;" does create prototype inheritance,
but with only 2 levels: Person and Object. The inheritance from Ninja and
Person is the exact same.
function Person(){}
function Ninja(){}
Ninja.prototype=new Person();
var ninjaNew=new Ninja();
console.log('ninjaNew');
console.log(
ninjaNew.__proto__===Ninja.prototype
); //true
console.log(
ninjaNew.__proto__.__proto__===Person.prototype
); //true
console.log(
ninjaNew.__proto__.__proto__.__proto__===Object.prototype
); //true
Ninja.prototype=Person.prototype;
var ninjaProto=new Ninja();
console.log('ninjaProto');
console.log(
ninjaProto.__proto__===Ninja.prototype
); //true
console.log(
ninjaProto.__proto__===Person.prototype
); //true
console.log(
ninjaProto.__proto__.__proto__===Person.prototype
); //false
console.log(
ninjaProto.__proto__.__proto__===Object.prototype
); //true
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Does copying the prototype reference from another constructor function maintain the prototype chain? GGolf <invalid@invalid.com> - 2013-01-05 12:39 +0530
Re: Does copying the prototype reference from another constructor function maintain the prototype chain? JJ <jaejunks@nah.meh> - 2013-01-05 10:57 +0000
Re: Does copying the prototype reference from another constructor function maintain the prototype chain? David Mark <dmark.cinsoft@gmail.com> - 2013-01-05 06:44 -0800
Re: Does copying the prototype reference from another constructor function maintain the prototype chain? David Mark <dmark.cinsoft@gmail.com> - 2013-01-05 06:43 -0800
Re: Does copying the prototype reference from another constructor function maintain the prototype chain? John G Harris <john@nospam.demon.co.uk> - 2013-01-05 15:53 +0000
Re: Does copying the prototype reference from another constructor function maintain the prototype chain? David Mark <dmark.cinsoft@gmail.com> - 2013-01-05 08:51 -0800
Re: Does copying the prototype reference from another constructor function maintain the prototype chain? Scott Sauyet <scott.sauyet@gmail.com> - 2013-01-05 12:25 -0800
Re: Does copying the prototype reference from another constructor function maintain the prototype chain? Luc Yen <luc@goal.tw> - 2013-01-05 13:23 -0800
csiph-web