Also, check out:
http://www.someelement.com/2007/03/multiple-inheritance-with-prototypejs.html

This is my rendition of Kevin Lindsey's inheritance model, designed to
support multiple inheritance and play well with prototype.js

For what you're talking about, read the section near the bottom labeled "So
how can you override base class methods and make sure that the original base
class method still gets called?"

Object.extend works very well as a simple "bulk property" copying mechanism,
and as such does not need this extra jazz. I really think you're looking for
a true "inheritance model", which Object.extend has never been, nor really
should be morphed into, IMHO.


On 5/4/07, Jerod Venema <[EMAIL PROTECTED]> wrote:
>
> Greetings!
>
> Nice bit of code there! You may want to check out this:
>
> http://www.ivy.fr/js/extend/index.html
>
> if you're going down that road anyway...
>
> -Jerod
>
> On 5/4/07, Tomasz R. <[EMAIL PROTECTED]> wrote:
> >
> >
> > Hi,
> >
> > I've recently started using prototype.js, but I've been doing "AJAX"
> > for long time now.
> >
> > I've inspected the prototype.js code, and I think I've got an
> > interesting addition to the Object.extend.
> > I might have reinvent the wheel here, so if it's nothing new please
> > give me some pointers as to how to accomplish the same with the native
> > prototype.js code.
> >
> > Basically, I was looking for a way to call the original function of an
> > extended object. Here is my modification:
> >
> > // a new version of extend
> >
> > Object.extend2 = function(destination, source) {
> >
> >   for (var property in source) {
> >           if(destination[property]) {
> >                   if(!destination['__super']) {
> >                         destination['__super'] = {};
> >                   }
> >                 destination['__super'][property] =
> > destination[property];
> >           }
> >           destination[property] = source[property];
> >   }
> >   return destination;
> > }
> >
> > // code to be executed to see the behavior.
> > var a = Class.create();
> > a.prototype = {
> >         initialize: function(name,link) {
> >                 this.elements = new Object();
> >         },
> >         test: function() {
> >                 alert('hello');
> >         }
> > }
> >
> > var b = Class.create();
> > b.prototype = Object.extend2(new a(), {
> >                 initialize: function() {
> >
> >                 },
> >
> >                 test: function() {
> >                         this.__super.test();
> >                         alert('hello2');
> >                 }
> >         }
> > )
> >
> > var B = new b();
> > B.test();
> >
> > // END
> >
> > after executing this code, you should first see the "hello" alert, and
> > then "hello2".
> >
> > I think this is an interesting addition, since I find myself often in
> > need to be able to access methods of the original object, without
> > having to copy/paste it's behavior to the new one.
> >
> >
> >
> >
> >
>
> >
>


-- 
Ryan Gahl
Software Architect
WebWidgetry.com / MashupStudio.com
Future Home of the World's First Complete Web Platform
Inquire: 1-262-951-6727
Blog: http://www.someElement.com

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype: Core" group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to