Hi,
We''ve considered similar implementations when developing Prototype 1.6
but opted for the current syntax instead.
Best,
Tobie
Tobias Nurmiranta wrote:> Hi. I''ve been playing around a bit with the super-operator in
> prototype, and made an alternative implementation. Classes with
> subclasses gets and extra hash super which contains all methods that
> are overloaded in the subclass.
>
> // Example
> var X = Class.create({
> initialize: function(x) {
> this.x = x;
> }
> });
>
> var Y = Class.create(X, {
> initialize: function(x, y) {
> this.super.initialize(x); // calling the overloaded function.
> this.y = y;
> }
> });
>
> I think this way is a bit more convenient, since you can call the
> superclass functions from anywhere. Any comments on the design choice?
>
> Have a nice day,
> Tobias
>
>
> // Modifications, (+ adding prototype.super = {} in Class.create)
> Class.Methods = {
> addMethods: function(source) {
> var ancestor = this.superclass && this.superclass.prototype;
>
> for (var property in source) {
> if(ancestor && ancestor[property])
> this.prototype.super[property] >
ancestor[property].bind(this.prototype);
>
> this.prototype[property] = source[property];
> }
>
> return this;
> }
> };
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---