Backbone Extend

by Sam Fereday

JavaScript

// Doesn't work at all.
var hasConstructor = function(props) {

	// etc etc

}

var extend = function(protoProps, staticProps) {

	var parent = this;
  var child;
  
  if(protoProps && hasConstructor(protoProps)) {
  	child = protoProps.constructor;
  } else {
  	child = function() { return parent.apply(this, arguments); };
  }
  
  // Some sort of property assigner method here
  
  child.prototype = Object.create(parent.prototype, protoProps);
  child.prototype.constructor = child;
  
  return child;

}