]> git.r.bdr.sh - rbdr/dotfiles/blob
1ef5756423cd361bf27c6d2ce3ce26ee609b738f
[rbdr/dotfiles] /
1 'use strict';
2
3 var value = require('./valid-value')
4 , mixin = require('./mixin')
5
6 , defineProperty = Object.defineProperty
7 , getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor
8 , getOwnPropertyNames = Object.getOwnPropertyNames
9 , getPrototypeOf = Object.getPrototypeOf
10 , hasOwnProperty = Object.prototype.hasOwnProperty;
11
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;
18 try {
19 mixin(target, source);
20 } catch (e) { error = e; }
21 source = getPrototypeOf(source);
22 define = function (name) {
23 if (hasOwnProperty.call(target, name)) return;
24 try {
25 defineProperty(target, name, getOwnPropertyDescriptor(source, name));
26 } catch (e) { error = e; }
27 };
28 while (source && (source !== end)) {
29 getOwnPropertyNames(source).forEach(define);
30 source = getPrototypeOf(source);
31 }
32 if (error) throw error;
33 return target;
34 };