Cédric Bertolini wrote:
> Well, I had never seen this pattern before:
> function Admin(first, last)  {
>     Person.call(this, first, last);
> }
>
> It's interesting, but you're making a lot of assumptions about Person. You
> can only use that if you thightly control Person and Admin.

Not exactly.  You would only write this in writing Admin, so
presumably you control that.  And you would have to thoroughly
understand the implications of calling the Person constructor.  But
you wouldn't have to control the Person constructor at all.
Obviously, if it changed, Admin might also need to change, but that's
true of any change to any public API.



> >   function F() {}
> >   F.prototype = Person.prototype;
> >   Admin.prototype = new F();
>
> Person.prototype is empty in your example.

I didn't bother to write anything, but it exists, and if you like, we
can add:

    Person.prototype.greet = function() {
      alert ("Hello, " + this.firstName);
    }

This would be inherited by all Admins as well as any other Person
objects.


> This instruction won't build a
> prototype chain between Admin and Person, only between Admin and
> Person.prototype, which is {}.

Really by definition, a prototype chain exists between
prototypes.  :-)


> Anyway, you are right in saying that currying the constructor doesn't build
> a prototype chain between Admin and Person. But going further in this
> direction will only lead us to recreate Class.create and al.

I didn't say this.  Honestly, because of my other objections, I hadn't
looked closely enough at it to notice.  But you're quite right that
with the code as presented, object constructed from Admin would not
inherit from Person.  It would not be hard to fix, though:

    var Admin = (function() {
      var F = function() {};
      F.prototype = Person.prototype;
      var constructor = Person.curry('admin');
      constructor.prototype = new F();
      return constructor;
    })();

    var admin = new Admin("Jane", "Doe");

This fixes the inheritance issue, but it still requires Person to be
designed for extension by things like Admin.  And if you need
additional parameters for ExecutiveAdmin, you'd have to update Admin
and Person.

> I'm afraid I don't know what Anatoly meant by "currying the prototype".

Me neither.  Anatoly, are you still around?

  -- Scott

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/jsmentors@jsmentors.com/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/jsmentors@googlegroups.com/

To unsubscribe from this group, send email to
jsmentors+unsubscr...@googlegroups.com

Reply via email to