Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • Suppose that object A is object B's prototype and object B is object C's prototype and you add a method to A. Then C can call that method.

    This sure looks like inheritance to me!

    • That was my first thought too but *technically* C is a clone of B which is a clone of A, so there is no inheritance. Wikipedia's page on prototype programming ( helped clarify it for me.

      • Sorry, but your technicality is simply wrong. If C was simply a clone of B then after the cloning operation B and C would be separate but equal. But if you create C then add properties to B, C will see those new properties. The converse is not true, new properties added to C are not visible to B. The relationship between an object and its prototype in JavaScript is not a straightforward cloning operation. Instead the newly created object (ahem) inherits properties from the prototype, which may in turn have inherited them from its prototype.

        JavaScript, The Definitive Guide [] explains this in some detail and uses the word "inheritance" for it.

        If that is not formal enough for you, go look at the official spec [] and read through that. Page 3, paragraph paragraph 2 starts with the statement, "ECMAScript supports prototype-based inheritance." (Emphasis in original.) You're going to have a difficult time convincing me that what JavaScript does shouldn't be called inheritance when it is called that in its own official specification! Certainly you won't do it by pointing me at a Wikipedia article which says, Example of true prototypal inheritance style in javascript.