3 var value = require('./valid-value')
4 , mixin = require('./mixin')
6 , defineProperty = Object.defineProperty
7 , getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor
8 , getOwnPropertyNames = Object.getOwnPropertyNames
9 , getPrototypeOf = Object.getPrototypeOf
10 , hasOwnProperty = Object.prototype.hasOwnProperty;
12 module.exports = function (target, source) {
13 var error, end, define;
14 target = Object(value(target));
15 source = Object(value(source));
16 end = getPrototypeOf(target);
17 if (source === end) return target;
19 mixin(target, source);
20 } catch (e) { error = e; }
21 source = getPrototypeOf(source);
22 define = function (name) {
23 if (hasOwnProperty.call(target, name)) return;
25 defineProperty(target, name, getOwnPropertyDescriptor(source, name));
26 } catch (e) { error = e; }
28 while (source && (source !== end)) {
29 getOwnPropertyNames(source).forEach(define);
30 source = getPrototypeOf(source);
32 if (error) throw error;