Re: Prototype OOP example

QnA
Sun, 25 Dec 2005 06:04:12 -0000

Hi Cliff,

Thank you for your example. It is a bit disappointed to me that it is not
possible to call the superclass''s constructor in prototype.
So may anyone know how to use the "bind" function? I was wondering if
it is
anything related to inheritance.

Merry Christmas and happy coding to all of you.

Regards,
QnA


2005/12/25, Cliff Mees
<cliff.mees-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:
>
> Here''s one approach:
>
> Labour = Class.create();
> Labour.prototype = {
>   initialize: function(name) {
>     this.name = name;
>   },
>   showMeYourName: function() {
>     alert(this.name);
>   }
> }
>
> Worker = Class.create();
> Worker.prototype = Object.extend(Labour.prototype, {
>   initialize: function(name, position) {
>     this.name = name;
>     this.position = position;
>   },
>   showMeYourPosition: function() {
>     alert(this.position);
>   }
> });
>
> var labour = new Labour(''Bob'');
> labour.showMeYourName();
>
> var worker = new Worker(''Joe'', ''Boss'');
> // call "base" class method
> worker.showMeYourName();
> // ... and invoke new Worker class method
> worker.showMeYourPosition();
>
>
>
>
> This just replaces the existing initialize with a derived version.
> There''s no provision to call Labour.initialize in
Worker.initialize.  You
> do get everything else though...
>
>
> Cliff
>
>
>
>  On Dec 24, 2005, at 14:49, QnA wrote:
>
>  Hi,
>
> Here is what I want to do:
>
> Labour = Class.create();
> Labour.prototype = {
>     initialize:function(name){
>         this.name = name;
>     }
> }
>
>
> What I want to do is create a class called "Worker" which will
inherit
> from "Labour", and the signature of "initialize" is
"function(name,
> position)".
>
> May I ask what should do?
>
>
> Thank you all very much for the kindly help.
> Wish you all with a Merry Christmas.
>
>
> Regards,
> QnA