m7v
4/8/2014 - 6:35 AM

Extend in JavaScript

Extend in JavaScript

/**
 * Generic object inheritance helper.
 */
var extend = function (child, parent) {
  function Child() {
    this.constructor = child;
  }

  var J = {}.hasOwnProperty;
  for (var e in parent) J.call(parent, e) && (child[e] = parent[e]);
  Child.prototype = parent.prototype;
  child.prototype = new Child;
  child.__super__ = parent.prototype;
  return child;
};