Wednesday, May 24th, 2006

Prototype Class System

Category: Articles, Prototype

Dean Edwards came up with Base as a way to give nice inheritence management in JavaScript.

He has tweaked it again.

I’ve made a couple of tweaks to the class since I last blogged about it. The most important change is that I’ve renamed the inherit method to base. I caved in to pressure.

These are the other small changes:

  • added a method to make multiple inheritance (yuk) easier
    javascript

    1. FlyingFish = Fish.extend();
    2. FlyingFish.implement(Bird);
  • the Base constructor function can now be used to cast an object to a Base object
    javascript

    1. var widget = document.getElementById("my-widget");
    2. Base(widget);
    3. widget.extend({
    4. ...
    5. });
  • constructor functions are now inherited (my bad)

Sam Stephenson of Prototype has started blogging and discussed the issues that he has with current inheritence in Prototype, and how Base could become part of Prototype 2.0.

Posted by Dion Almaer at 9:03 am
4 Comments

++++-
4.2 rating from 31 votes

4 Comments »

Comments feed TrackBack URI

[…] Ajaxian » Prototype Class System (tags: javascript prototype programming inheritance class development Ajax) […]

Pingback by links for 2006-05-25 at /dev/caffeine — May 24, 2006

Extend/Base is seems wasteful as it’s copied into each object that ‘extends’ from it and does not seem to make good use of the refrence objects/methods, ie prototype (the actual prototype, not the framework)

Comment by Dave — May 30, 2006

@Dave – You are mistaken. Base uses prototype based inheritance.

Comment by Dean Edwards — June 5, 2006

[…] Ajaxian Prototype Class SystemAjaxian Prototype Class System (tags: javascript prototype programming inheritance class development Ajax) [ ] Pingback by links for 2006-05-25 at /dev/caffeine May 24, 2006 […]

Pingback by Prototype » Prototype Laboratory — July 11, 2006

Leave a comment

You must be logged in to post a comment.