I do this stuff all the time just using proto. There''s nothing magical
about
Douglas''s methods, although it''s cool he got there 5 years
ago... the
"method" method, is just a shortcut for assigning a property of a
prototype,
and the swiss method is merely Object.extend() with a filter.
In the same order as the article from the link...
Parenizor = Class.create();
Parenizor.prototype {
    initialize: function(value)
    {
        this.setValue(value);
    },
    setValue: function(value)
    {
        this.value = value;
    },
    getValue: function()
    {
        return this.value;
    },
    _toString: function()
    {
        return "(" + this.value + ")";
    }
};
ZParenizor = Class.create();
ZParenizor.prototype {
    initialize: function(value)
    {
        //cache the super class
        this.base = new Parenizor(value);
        //inherit
        Object.extend(this, this.base);
        //override
        Object.extend(this,
        {
            _toString: function()
            {
                if (this.getValue())
                    return this.base._toString();
                return "-0-";
            }.bind(this)
        });
    }
};
alert(new ZParenizor(5)._toString());
alert(new ZParenizor()._toString());
--for Swiss inheritance, just explicitly extend your class with only the
methods you want...
ZParenizor = Class.create();
ZParenizor.prototype {
initialize: function(value)
{
var numberValue = new NumberValue(value);
Object.extend(this, {setValue: numberValue.setValue, setRange:
numberValue.setRange});
}
};
...the rest of the article is so obviously covered in proto (or already by
my code above), it''s not worth my going on...
On 6/9/06, Martin Bialasinski
<klingeling-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:>
> On 6/9/06, Ryan Gahl
<ryan.gahl-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> > was just pointing out that proto
> > does all that stuff
>
> No. Prototype.js actually does far less than the methods described in
> Douglas'' article, you must have misread it. The current prototype
> implementation is at the bottom end of what is possible. And as you
> have noticed, the article is five years old.
> _______________________________________________
> Rails-spinoffs mailing list
> Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
>
_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs