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." <[email protected]> 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 [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~----------~----~----~----~------~----~------~--~---
