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. > > > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---