If you're going to add a beget() function, you ought to plan for how it is going to interact with the Object.create() function coming in es5... My concern is that it will be confusing to have functions like beget that take plain objects as sets of properties to copy when Object.create() takes a set of property descriptors instead. I suggest that you might want to keep object creation and object extension separate and require an idiom like this:
$.extend($.beget(proto), props) David Andrea Giammarchi wrote: > Dunno how many times that bedge has been optimized ;-) > > (function(){ > var F = function(){}; > jQuery.beget = function (proto, props) { > F.prototype = proto; > return props ? $.extend(new F, props) : new F; > }; > })(); > > Regards > > > On Thu, Jul 30, 2009 at 3:48 PM, Már Örlygsson <mar.orlygs...@gmail.com > <mailto:mar.orlygs...@gmail.com>> wrote: > > > Hi. > If it hasn't been already considered (and rejected), I'd like to float > the idea of adding support for prototypal inheritance into the jQuery > core library. > > Something like this... > > jQuery.beget = function (proto, props) { > var F = function () {}; > F.prototype = proto; > var instance = new F(); > return props ? $.extend(instance, props) : instance; > }; > > ...becomes immensely powerful - especially during plugin development > when allowing users to extend/override default options > > options = $.beget($.myplugin.defaults, options || {}); > > ...and in various other common use cases - including $.fn.data() > assignments, etc. > > > I for one would love to see this feature added. > > -- > Már > > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "jQuery Development" group. To post to this group, send email to jquery-dev@googlegroups.com To unsubscribe from this group, send email to jquery-dev+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en -~----------~----~----~----~------~----~------~--~---