If there is functionality in the base class's constructor that, for instance, prepares the object instance (initializes an XHR object, etc..), or otherwise must execute, then use an instance. This is yet another "use what works for the situation" things... I use both methods frequently.

I also use the instance method from within the subclass constructor sometimes (vs. from the Object.extend top portion), for instance if both constructors take arguments and the subclass needs to somehow calculate the value of one of the base class constructor's arguments.

Object.extend(SubClass.prototype, {
initialize: function(id, options) {
//do some stuff that determines the value of "foo"
Object.extend (this, new Testing(id, options, foo));
}
});

On 5/24/06, Jeremy Kitchen <[EMAIL PROTECTED] > wrote:
when using prototype and Class.create(), what's the preferred method of
creating a subclass?

say I have a real simple class:
var Testing = Class.create();
Object.extend(Testing.prototype, {
    initialize: function() {
        ...
    },
    ...
});

would I subclass it as so?
var SubClass = Class.create();
Object.extend(Object.extend(SubCLass.prototype, Testing.prototype), {
    ...
});

or would I replace Testing.prototype above with new Testing() ?

The reason I ask this is because I think I've seen it both ways in
script.aculo.us, and they both appear to work, but I would think that
creating an instance of the class might not be such a good idea because it
might modify some state on the page or whatnot...

Thanks :)

-Jeremy

--
Jeremy Kitchen ++ [EMAIL PROTECTED]

http://ipaction.org/ -- defend your rights to fair use


_______________________________________________
Rails-spinoffs mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs




_______________________________________________
Rails-spinoffs mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs

Reply via email to