Richard Quadling
2008-Apr-28 09:15 UTC
Re: [Rails Trac] #11481: [PATCH] [TEST] Constructor wrapper should return value
2008/4/28 Rails Trac <trac-cl546fv4r9ei4IrrL8KYoA@public.gmane.org>:> #11481: [PATCH] [TEST] Constructor wrapper should return value > ---------------------------------------------------+------------------------ > Reporter: cch1 | Owner: sam > Type: defect | Status: closed > > Priority: normal | Milestone: 2.x > Component: Prototype | Version: edge > Severity: normal | Resolution: wontfix > > Keywords: TRIVIAL constructor initialize return | > ---------------------------------------------------+------------------------ > Changes (by jdalton): > > * status: new => closed > * resolution: => wontfix > > Comment: > > After some discussions I don''t believe this will ever make it into the > core. > > -- > Ticket URL: <http://dev.rubyonrails.org/ticket/11481#comment:9>In general, having class X being able to return class Y can be very useful (implementing a factory for example). I''m not saying that this SHOULD go in, but what are the primary reasons for NOT putting it in? Thanks. Richard Quadling. -- ----- Richard Quadling Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 "Standing on the shoulders of some very clever giants!" --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
kangax
2008-Apr-28 12:09 UTC
Re: #11481: [PATCH] [TEST] Constructor wrapper should return value
Richard,
returning alien object from the constructor could actually be quite
confusing:
var Person = Class.create({
initialize: function(name) {
this.name = name;
return { foo: ''bar'' };
},
speak: function(msg) {
return [this.name, msg].join('': '');
}
})
var john = new Person(''John'');
// broken prototype chain
john instanceof Person; // false
john.constructor == Person; // false
// missing instance properties/methods
john.name; // undefined
john.speak; // undefined
// returned object has nothing to do with the Person class
john.foo; // ''bar''
As far as factory pattern, I don''t think it''s a good idea for
a class
X to return class Y. Wouldn''t it make more sense to have an instance
of class "Factory" that could return either X or Y?
On Apr 28, 5:15 am, "Richard Quadling"
<rquadl...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>
wrote:> 2008/4/28 Rails Trac <t...-cl546fv4r9ei4IrrL8KYoA@public.gmane.org>:
>
>
>
> > #11481: [PATCH] [TEST] Constructor wrapper should return value
> >
---------------------------------------------------+------------------------
> > Reporter: cch1 | Owner:
sam
> > Type: defect | Status:
closed
>
> > Priority: normal | Milestone:
2.x
> > Component: Prototype | Version:
edge
> > Severity: normal | Resolution:
wontfix
>
> > Keywords: TRIVIAL constructor initialize return |
> >
---------------------------------------------------+------------------------
> > Changes (by jdalton):
>
> > * status: new => closed
> > * resolution: => wontfix
>
> > Comment:
>
> > After some discussions I don''t believe this will ever make
it into the
> > core.
>
> > --
> > Ticket URL: <http://dev.rubyonrails.org/ticket/11481#comment:9>
>
> In general, having class X being able to return class Y can be very
> useful (implementing a factory for example).
>
> I''m not saying that this SHOULD go in, but what are the primary
> reasons for NOT putting it in?
>
> Thanks.
>
> Richard Quadling.
>
> --
> -----
> Richard Quadling
> Zend Certified Engineer
:http://zend.com/zce.php?c=ZEND002498&r=213474731
> "Standing on the shoulders of some very clever giants!"
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Richard Quadling
2008-Apr-28 12:12 UTC
Re: #11481: [PATCH] [TEST] Constructor wrapper should return value
2008/4/28 kangax <kangax-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:> > Richard, > returning alien object from the constructor could actually be quite > confusing: > > var Person = Class.create({ > initialize: function(name) { > this.name = name; > return { foo: ''bar'' }; > }, > speak: function(msg) { > return [this.name, msg].join('': ''); > } > }) > > var john = new Person(''John''); > > // broken prototype chain > john instanceof Person; // false > john.constructor == Person; // false > > // missing instance properties/methods > john.name; // undefined > john.speak; // undefined > > // returned object has nothing to do with the Person class > john.foo; // ''bar'' > > As far as factory pattern, I don''t think it''s a good idea for a class > X to return class Y. Wouldn''t it make more sense to have an instance > of class "Factory" that could return either X or Y? >Aha! Of course. And that''s why it is a Factory Method. Doh. Good point. Well made. Thank you. Richard.> On Apr 28, 5:15 am, "Richard Quadling" <rquadl...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> > wrote: > > 2008/4/28 Rails Trac <t...-cl546fv4r9ei4IrrL8KYoA@public.gmane.org>: > > > > > > > > > > > #11481: [PATCH] [TEST] Constructor wrapper should return value > > > ---------------------------------------------------+------------------------ > > > Reporter: cch1 | Owner: sam > > > Type: defect | Status: closed > > > > > Priority: normal | Milestone: 2.x > > > Component: Prototype | Version: edge > > > Severity: normal | Resolution: wontfix > > > > > Keywords: TRIVIAL constructor initialize return | > > > ---------------------------------------------------+------------------------ > > > Changes (by jdalton): > > > > > * status: new => closed > > > * resolution: => wontfix > > > > > Comment: > > > > > After some discussions I don''t believe this will ever make it into the > > > core. > > > > > -- > > > Ticket URL: <http://dev.rubyonrails.org/ticket/11481#comment:9> > > > > In general, having class X being able to return class Y can be very > > useful (implementing a factory for example). > > > > I''m not saying that this SHOULD go in, but what are the primary > > reasons for NOT putting it in? > > > > Thanks. > > > > Richard Quadling. > > > > -- > > ----- > > Richard Quadling > > Zend Certified Engineer :http://zend.com/zce.php?c=ZEND002498&r=213474731 > > "Standing on the shoulders of some very clever giants!" > > >-- ----- Richard Quadling Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 "Standing on the shoulders of some very clever giants!" --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---