Code coverage report for bookshelf/lib/extend.js

Statements: 100% (23 / 23)      Branches: 90% (9 / 10)      Functions: 100% (2 / 2)      Lines: 100% (22 / 22)      Ignored: none     

All files » bookshelf/lib/ » extend.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52        1 693 693         693 9   684 209534         693   693 693   693 1598 1598       693 33   33 48 48         693     693       693   693  
 
// Uses a hash of prototype properties and class properties to be extended.
"use strict";
 
module.exports = function (protoProps, staticProps) {
  var parent = this;
  var child;
 
  // The constructor function for the new subclass is either defined by you
  // (the "constructor" property in your `extend` definition), or defaulted
  // by us to simply call the parent's constructor.
  if (protoProps && protoProps.hasOwnProperty('constructor')) {
    child = protoProps.constructor;
  } else {
    child = function () {
      parent.apply(this, arguments);
    };
  }
 
  // Set the prototype chain to inherit from `Parent`
  child.prototype = Object.create(parent.prototype);
 
  Eif (protoProps) {
    var i = -1,
        keys = Object.keys(protoProps);
    while (++i < keys.length) {
      var key = keys[i];
      child.prototype[key] = protoProps[key];
    }
  }
 
  if (staticProps) {
    var i = -1,
        keys = Object.keys(staticProps);
    while (++i < keys.length) {
      var key = keys[i];
      child[key] = staticProps[key];
    }
  }
 
  // Correctly set child's `prototype.constructor`.
  child.prototype.constructor = child;
 
  // Add static properties to the constructor function, if supplied.
  child.__proto__ = parent;
 
  // If there is an "extended" function set on the parent,
  // call it with the extended child object.
  if (typeof parent.extended === "function") parent.extended(child);
 
  return child;
};