You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
607 B
25 lines
607 B
"use strict"; |
|
|
|
var value = require("./valid-value") |
|
, mixin = require("./mixin"); |
|
|
|
var getPrototypeOf = Object.getPrototypeOf; |
|
|
|
module.exports = function (target, source) { |
|
target = Object(value(target)); |
|
source = Object(value(source)); |
|
if (target === source) return target; |
|
|
|
var sources = []; |
|
while (source && !isPrototypeOf.call(source, target)) { |
|
sources.unshift(source); |
|
source = getPrototypeOf(source); |
|
} |
|
|
|
var error; |
|
sources.forEach(function (sourceProto) { |
|
try { mixin(target, sourceProto); } catch (mixinError) { error = mixinError; } |
|
}); |
|
if (error) throw error; |
|
return target; |
|
};
|
|
|