2008/4/28 kangax <[EMAIL PROTECTED]>:
>
> 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" <[EMAIL PROTECTED]>
> wrote:
> > 2008/4/28 Rails Trac <[EMAIL PROTECTED]>:
>
>
> >
> >
> >
> > > #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 [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---