all files / lib/offshore/utils/ extend.js

94.12% Statements 16/17
66.67% Branches 4/6
100% Functions 3/3
92.86% Lines 13/14
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                741× 741×   741×     5155×     741×   741× 741× 741×   741×   741×   741×    
/**
 * Extend Method
 *
 * Taken from Backbone Source:
 * http://backbonejs.org/docs/backbone.html#section-189
 */
 
var _ = require('lodash');
 
module.exports = function(protoProps, staticProps) {
  var parent = this;
  var child;
 
  Iif (protoProps && _.has(protoProps, 'constructor')) {
    child = protoProps.constructor;
  } else {
    child = function() { return parent.apply(this, arguments); };
  }
 
  _.extend(child, parent, staticProps);
 
  var Surrogate = function() { this.constructor = child; };
  Surrogate.prototype = parent.prototype;
  child.prototype = new Surrogate();
 
  Eif (protoProps) _.extend(child.prototype, protoProps);
 
  child.__super__ = parent.prototype;
 
  return child;
};