ES5 + .extend is not necessary for this simple chunk. (function($){ if (!Object.create) var F = function(){}; $.beget = function (proto, props) { if(Object.create) var o = Object.create(proto); else { F.prototype = proto; var o = new F; } for ( var k in props ) o[k] = props[k]; return o; }; })(jQuery);
~Daniel Friesen (Dantman, Nadir-Seen-Fire) [http://daniel.friesen.name] 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 -~----------~----~----~----~------~----~------~--~---