Re: Prototype OOP example

Cliff Mees
Sun, 25 Dec 2005 13:17:56 -0000

Hi,

Bind and related bits are very well explained here:

http://www.deepwood.net/writing/method-references.html.utf8

Merry Christmas everyone!

Cliff


On Dec 25, 2005, at 01:04, QnA wrote:

> 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
>> _______________________________________________
>> Rails-spinoffs mailing list
>> Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
>> http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs