Dziedziczenie obiektów w JavaScript

Moje pytanie dotyczy obiektu podrzędnego utrzymującego łańcuch prototypu jego obiektu nadrzędnego.

W Zaawansowanych slajdach JavaScript Johna Resiga (http://ejohn.org/apps/learn/#76) pisze, że w celu utrzymania łańcucha prototypów obiektu podrzędnego należy utworzyć instancję nowego obiektu nadrzędnego.

Jednak dzięki kilku szybkim testom zauważyłem, że łańcuch prototypów jest utrzymywany przez ustawienie prototypu obiektu podrzędnego równego prototypowi obiektu nadrzędnego.

Wszelkie wyjaśnienia byłyby bardzo mile widziane!

Oryginalny kod

function Person(){}
Person.prototype.dance = function(){};

function Ninja(){}

// Achieve similar, but non-inheritable, results
Ninja.prototype = Person.prototype;
Ninja.prototype = { dance: Person.prototype.dance };

assert( (new Ninja()) instanceof Person, "Will fail with bad prototype chain." );

// Only this maintains the prototype chain
Ninja.prototype = new Person();

var ninja = new Ninja();
assert( ninja instanceof Ninja, "ninja receives functionality from the Ninja prototype" );
assert( ninja instanceof Person, "... and the Person prototype" );
assert( ninja instanceof Object, "... and the Object prototype" );

Moja zmodyfikowana wersja

function Person(){}
Person.prototype.dance = function(){console.log("Dance")};

function Ninja(){}

// Achieve similar, but non-inheritable, results
Ninja.prototype = Person.prototype;

assert( (new Ninja()) instanceof Person, "Will fail with bad prototype chain." );

var ninja = new Ninja();
assert( ninja instanceof Ninja, "ninja receives functionality from the Ninja prototype" );
assert( ninja instanceof Person, "... and the Person prototype" );
assert( ninja instanceof Object, "... and the Object prototype" );
ninja.dance();

questionAnswers(2)

yourAnswerToTheQuestion