Thanks, that's really great, I'll have to really play around with that
when I've got the time to really get to grips with it.  Can you do
multiple inheritence with that trick?


On Jun 25, 3:13 pm, Christof Donat <[EMAIL PROTECTED]> wrote:
> Hi,
>
> > Okay, thanks for the help.  I was just trying to figure out how to do
> > inheritence in javascript and instead embedded objects inside other
> > objects.  :)
>
> Ah, what you are looking for is this:
>
> function super() { /*...*/ };
> super.prototype = {
>         varA: 'a',
>         varB: 'b'}
>
> function sub() { /*...*/ };
> sub.prototype = new super(); // this is equivalent to inheritance
>
> // we can not simply assign an object to prototype now, because that would
> // overwrite the existing prototype. Use jQuery.extend(sub.prototype,{...});
> // wherever you have jQuery available.
> sub.prototype['var1'] = 1;
> sub.prototype['var2'] = 2;
> sub.prototype['method1'] = function() {
>         alert(this.varA); // yes, now we have this.varA
>
> };
>
> (new sub()).method1(); // will alert 'a'.
>
> Christof

Reply via email to