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.

mixin-prototypes.js 607B

12345678910111213141516171819202122232425
  1. "use strict";
  2. var value = require("./valid-value")
  3. , mixin = require("./mixin");
  4. var getPrototypeOf = Object.getPrototypeOf;
  5. module.exports = function (target, source) {
  6. target = Object(value(target));
  7. source = Object(value(source));
  8. if (target === source) return target;
  9. var sources = [];
  10. while (source && !isPrototypeOf.call(source, target)) {
  11. sources.unshift(source);
  12. source = getPrototypeOf(source);
  13. }
  14. var error;
  15. sources.forEach(function (sourceProto) {
  16. try { mixin(target, sourceProto); } catch (mixinError) { error = mixinError; }
  17. });
  18. if (error) throw error;
  19. return target;
  20. };