However, you could employ a slightly more traditional approach, which is to
leave the first version of A as the base class, and then subclass it as

(Btw, the way you have written A below is as a static object, and as such
you are gaining nothing by using Class.create(). Class.create() points the
constructor for the class at an "initialize" method on the class's
prototype, which of course you never define)

Try something like this (notice that I define public class level instance
methods within the constructor to ensure they are truly only given to
instances of the class):

var A = Class.create();
A.prototype = {
initialize: function() {
//public instance members = function() {
alert("I am A");

var B = Class.create();
Object.inherit(A, B);
Object.extend(B.prototype, {
initialize: function() {
//base class construction

//override show
var oldShow =; = function() {
alert("I am EXTENDED A");

var test = new B();; // alerts "I am A" and "I am EXTENDED A"

This technique comes right from by blog post on the inheritance model.

Now, if you're looking to tack (or override) methods on existing
instances... you don't need a special addPlugin() method like what you
started doing. You can just take advantage of plain old javascript...

(Assume we are back to using the definition of A from your original post)...

var oldShow =; = function() {
alert("I am EXTENDED A");

Notice in my first example (the object oriented approach), and in this
example (the static object version) I use a .bind() call. Doing so ensures
that if ever tried to access "this", it would still point to the
correct scope.

For instance, imagine looked like this:

function() {

Ok... so I'll stop now I guess, just realize this list isn't really supposed
to be a support list. :-)

Hope this has helped though.

You received this message because you are subscribed to the Google Groups 
"Prototype: Core" group.
To post to this group, send email to
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at

Reply via email to