Object.extend equivelant

5 views
Skip to first unread message

kstubs

unread,
Nov 7, 2009, 1:21:37 PM11/7/09
to Prototype & script.aculo.us
The following is working, but I am looking for the pure prototypejs
equivelant. So, what would the equivilant code be for

var GymnastFind = Class.create();
Object.extend(Object.extend(GymnastFind.prototype,
GridBuild.prototype));
Object.extend(Object.extend(GymnastFind.prototype,
Ajax.Application.Base.prototype), {
HEAD: ['MSOID', 'USAG', 'Description', 'DOB'],
initialize: function(container, url) {
this.UserActive = false;
this.timer = null;
...... code cut here ......
});

In plain English:

Create a GymnastFind Class which inherits from GridBuild class and
implements the abstract class Ajax.Application.Base.

Thanks,
Karl..

T.J. Crowder

unread,
Nov 8, 2009, 4:45:27 AM11/8/09
to Prototype & script.aculo.us
Hi Karl,

Class.create accepts a base class and multiple mix-ins[1]. The way
JavaScript's instanceof operator works, you can't create a new class
from two disparate base classes and have the new class be an
"instanceof" both of the base classes, you have to choose one as a
base and mix-in the other, but that's fine if the code you quoted is
working for you, nothing is relying on instances of GymnastFind being
"instanceof" Ajax.Application.Base.

So if you want it to derive from GridBuild and mix-in
Ajax.Application.Base:

var GymnastFind = Class.create(GridBuild,
Ajax.Application.Base.prototype);

(Note that for the base class, we specify the class [the constructor
function] rather than the prototype, but mix-ins are specified just as
an object, so we use the prototype of Ajax.Application.Base.)

If you want to specify your own methods as well, just include them as
an object as a third parameter.

[1] http://api.prototypejs.org/language/class.html

HTH,
--
T.J. Crowder
Independent Software Consultant
tj / crowder software / com
www.crowdersoftware.com

kstubs

unread,
Nov 8, 2009, 9:18:42 PM11/8/09
to Prototype & script.aculo.us
If I do something like this:

var GymnastFind = Class.create(GridBuild,
Ajax.Application.Base.Prototype, UserState, {
HEAD: ['MSOID', 'USAG', 'Description', 'DOB'],
initialize: function(container, url) {
this.url = url;
this.container = $(container).select('div.grid_container')[0];
this.Form = $(container).select('form')[0]
this.Form.observe('keyup', this.form_keyup.bind(this));
},

... code cut here ...

I get an error in prototypejs, "parent.subclasses is undefied" (occurs
at line 99) the code is:

parent.subclasses.push(klass);


Any ideas? Maybe I can't mix in Ajax.Application.Base, maybe I must
inherit it? So am I correct in assuming that the Javascript allows
you to inherit from more than one class, an in my previous
"Object.extend(Object.extend ..." syntax I am doing just this?

Thanks for the help.
Karl..

kstubs

unread,
Nov 8, 2009, 9:35:15 PM11/8/09
to Prototype & script.aculo.us
UPDATE!

This works:
var GymnastFind =
Class.create(GridBuild.prototype,
Ajax.Application.Base.prototype,
UserState, {
HEAD: ['MSOID', 'USAG', 'Description', 'DOB'],
initialize: function(container, url) {
this.url = url;
this.container = $(container).select('div.grid_container')[0];
this.Form = $(container).select('form')[0]
this.Form.observe('keyup', this.form_keyup.bind(this));
},


Since GridBuild is declared as a function, then I suppose I am only
mixing in it's methods and not inheriting from it as a class.
Therefore I must refer to the prototype property of GridBuild, and
same thing for the Ajax.Application.Base object?

Karl..

On Nov 8, 2:45 am, "T.J. Crowder" <t...@crowdersoftware.com> wrote:

T.J. Crowder

unread,
Nov 9, 2009, 9:30:31 AM11/9/09
to Prototype & script.aculo.us
Hi,

> I get an error in prototypejs, "parent.subclasses is undefied" (occurs
> at line 99) the code is:
>
> parent.subclasses.push(klass);
>
> Any ideas?

The superclass (parent) must be a class that was defined with
Class.create; from that error, I'm thinking GridBuild is defined
"raw" (or in some other non-Class.create method).

HTH,

-- T.J. :-)

kstubs

unread,
Nov 9, 2009, 3:08:29 PM11/9/09
to Prototype & script.aculo.us
It is defined like this:

var GridBuild = function(){};

Object.extend(Object.extend(GridBuild.prototype, GridBase.prototype),
... code cut here ...

{
Reply all
Reply to author
Forward
0 new messages