• Как сделать правильный deep extend двух объектов у которых в свойствах очень глубокие объекты типа $('.some')?

    @fatedupi Автор вопроса
    deepExtend = function() {
    	var options, name, src, copy, copyIsArray, clone,
    			target = arguments[0] || {},
    			i = 1,
    			length = arguments.length,
    			deep = true;
    
    	for ( ; i < length; i++ ) {
    
    		if ( (options = arguments[ i ]) != null ) {
    			
    			for ( name in options ) {
    				src = target[ name ];
    				copy = options[ name ];
    				var descriptor = Object.getOwnPropertyDescriptor(options, name);
    				if(typeof descriptor.get !== 'undefined') {
    					Object.defineProperty(copy, name, descriptor);
    				}
    				
    				if ( target === copy ) {
    					continue;
    				}
    				if ( deep && copy && ( jQuery.isPlainObject(copy) || (copyIsArray = jQuery.isArray(copy)) ) && (typeof descriptor.get === 'undefined') ) {
    					if ( copyIsArray ) {
    						copyIsArray = false;
    						clone = src && jQuery.isArray(src) ? src : [];
    					} else {
    						clone = src && jQuery.isPlainObject(src) ? src : {};
    					}
    					//console.log(clone);
    					target[ name ] = deepExtend( clone, copy );
    
    				} else if ( copy !== undefined ) {
    					var descriptor = Object.getOwnPropertyDescriptor(options, name);
    					Object.defineProperty(target, name, descriptor);
    				}
    			}
    		}
    	}
    
    	return target;
    };


    что-то типа такого получилось, на основе jQuery.extend
    Ответ написан
    Комментировать