> I don't see how "var d = new A(B); " is "chunkier" than "var e = new > A(new (B));" : )
I guess it's a matter of taste then. I prefer Object.extend(this, obj) to Object.extend(this, obj.prototype), just wanted to know if there was really any difference in the two different approaches, and for the record both function identically. > Am I correct that you want to extend instance with methods, and > preserve their (methods') inheritance? Yeah that's spot on. On Apr 23, 10:53 pm, kangax <[EMAIL PROTECTED]> wrote: > Am I correct that you want to extend instance with methods, and > preserve their (methods') inheritance? > > - kangax > > On Apr 23, 7:22 am, Mike Rumble <[EMAIL PROTECTED]> wrote: > > > Hello, > > > I can't make my mind up over some finer points of an API design and > > would appreciate any feedback on my code. Hopefully this example is > > clear... > > > var A = Class.create({ > > initialize : function(obj){ > > Object.extend(this, obj) > > } > > > }); > > > var B = { > > method : function(){ > > .... > > } > > > }; > > > var C = { > > method: function(){ > > .... > > } > > > }; > > > var d = new A(B); > > var e = new A(C); > > > On initialization each instance of class A is extended with methods > > from a separate object via Object.extend. I've chosen not to use > > Class#addMethods because each instance of can be extended with a > > different object, and therefore the prototype chain of class A should > > remain unaffected. > > > So for so good. > > > However I'm looking to use this taking advantage of Prototype's > > inheritance features for the extension objects. I've currently got > > something that looks like this... > > > var A = Class.create({ > > initialize : function(obj){ > > Object.extend(this, obj.prototype) > > } > > > }); > > > var B = Class.create({ > > method : function(){ > > .... > > } > > > }) > > > var C = (B, { > > method: function($super){ > > $super(); > > } > > > }; > > > var d = new A(B); > > var e = new A(C); > > > It works OK but feels a little clunky. To me it would make more sense > > to do something like this... > > > var A = Class.create({ > > initialize : function(obj){ > > Object.extend(this, obj) > > } > > > }); > > > var B = Class.create({ > > method : function(){ > > .... > > } > > > }) > > > var C = (B, { > > method: function($super){ > > $super(); > > } > > > }; > > > var d = new A(new (B)); > > var e = new A(new (C)); > > > Anybody got any strong opinions on which approach is best? --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---