There appears to be a problem with Prototype''s Class.create();
Why can''t I set an instance variable NOT passed through the arguments?
I have the following code:
// JavaScript Document
var Person = Class.create(
{
initialize:function(age){
this.age = age;
},
identity:function(){
alert(''Hello, I am ''+this.age+'' years
old.'');
}
}
);
var NamedPerson = Class.create(
Person, {
initialize:function($super, name, age){
$super(age);
this.name = name;
},
identity:function(){
alert(''Hello, my Name is ''+this.name+''. I am
''+this.age+'' years
old.'');
alert(this.superclass.identity);
}
}
);
var FemaleNamedPerson = Class.create(
NamedPerson,
{
initalize:function($super, name, age){
$super(name, age);
this.sex = ''female'';
},
identity:function(){
alert(''Hello, my Name is ''+this.name+''. I am
''+this.age+'' years
old. I am a ''+this.sex+''.'');
}
}
);
var gina = new FemaleNamedPerson(''Gina'', 25);
gina.identity();//alerts Hello, My Name is Gina. I am 25 years old.
I am a undefined.
Shouldn''t gina.identity alert Hello, My Name is Gina. I am 25 years
old. I am a female.?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---
It appears that any instance properties can be added after
initialization has completed: for example:
identity:function(){
alert(''Hello, my Name is ''+this.name+''. I am
''+this.age+'' years
old. I am a ''+this.sex+''.'');
this.sex=''bob'';
}
the initial identity() call ends with "I am a undefined" but the
subsequent calls end with "I am a bob".
Wierd.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---
Jack wrote:> It appears that any instance properties can be added after > initialization has completed: for example: > identity:function(){ > alert(''Hello, my Name is ''+this.name+''. I am ''+this.age+'' years > old. I am a ''+this.sex+''.''); > this.sex=''bob''; > } > > the initial identity() call ends with "I am a undefined" but the > subsequent calls end with "I am a bob". > > Wierd. >I got the same result. It seems like the only explanation is a bug. I even tried defining a setSex() method and calling it from initialize, but it has no effect. It doesn''t even matter on which parent the setSex() method was defined. If it is a bug, your example seems to indicate a problem with scope or execution order for sub-subclasses. Can anyone else verify that Jack''s code demonstrates a bug with Prototype inheritance? -- Ken Snyder --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
God, that scared the hell out of me. Jack, you have a typo in FemaleNamedPerson. Change "initalize" to "initialize" and it''ll work just fine. ;-) Cheers, Andrew On Dec 7, 2:15 pm, Ken Snyder <kendsny...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Jack wrote: > > It appears that any instance properties can be added after > > initialization has completed: for example: > > identity:function(){ > > alert(''Hello, my Name is ''+this.name+''. I am ''+this.age+'' years > > old. I am a ''+this.sex+''.''); > > this.sex=''bob''; > > } > > > the initial identity() call ends with "I am a undefined" but the > > subsequent calls end with "I am a bob". > > > Wierd. > > I got the same result. It seems like the only explanation is a bug. I > even tried defining a setSex() method and calling it from initialize, > but it has no effect. It doesn''t even matter on which parent the > setSex() method was defined. > > If it is a bug, your example seems to indicate a problem with scope or > execution order for sub-subclasses. Can anyone else verify that Jack''s > code demonstrates a bug with Prototype inheritance? > > -- Ken Snyder--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Andrew Dupont wrote:> God, that scared the hell out of me. > > Jack, you have a typo in FemaleNamedPerson. Change "initalize" to > "initialize" and it''ll work just fine. ;-) > > Cheers, > Andrew >Yay! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Good spotting Andrew, I read through the source and didn''t even see it the first time until I knew to look for it. On Dec 8, 2007 10:47 AM, Ken Snyder <kendsnyder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Andrew Dupont wrote: > > God, that scared the hell out of me. > > > > Jack, you have a typo in FemaleNamedPerson. Change "initalize" to > > "initialize" and it''ll work just fine. ;-) > > > > Cheers, > > Andrew > > > Yay! > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---