Elegant sample. i guess with a minuscule need it's not worth having a permanent built-in toggle. But hey, if the need arises... Thanks! -joe t.
On Jan 7, 11:00 am, Tobie Langel <tobie.lan...@gmail.com> wrote: > http://gist.github.com/44308 > > I'd probably suggest another method, though, rather than adding a flag > to Object.extend. > > Best, > > Tobie > > On Jan 7, 3:45 pm, "joe t." <thooke...@gmail.com> wrote: > > > How would the core feel about a safe version of Object.extend? > > > Object.extend = function(destination, source, safe) { > > safe = !!safe || false; > > for (var property in source){ > > destination[property] = (safe && typeof destination[property] !== > > 'undefined') ? > > destination[property] : source[property]; > > } > > return destination; > > > }; > > > Existing functionality is covered (safe defaults false, which goes to > > source[property], no need to change anything. > > > i found a recent need to extend a class object after it had been > > created, but i didn't want to overwrite properties if they'd already > > been defined. i imagine there would be some minimal performance hit > > testing each property if safe==true, but otherwise...? Any visible > > problems? > > > Just a suggestion, it helped me out. > > -joe t. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Prototype: Core" group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to prototype-core-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~----------~----~----~----~------~----~------~--~---